Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rebol [title: "TabbyCalc"]
- title: "TabbyCalc"
- ;it's old code. don't judge me!
- parse-math: funct [str] [
- parse-math-replace-list: [
- "--" "+"
- "+-" "-"
- "*-" " * - "
- "/-" " / - "
- " e " "e"
- " e- " "e-"
- "^^" "** "
- ]
- op: charset "*/+-^^()e<>="
- ;e is an operation for exponents, eg 4e-2.
- ;consequently e cannot be a variable
- nop: complement op
- out: copy []
- a: none
- parse str [
- some [
- copy a some nop (append out a)
- | copy a some op (append out a)
- ]
- end
- ]
- out: form out
- foreach [a b] parse-math-replace-list [
- replace/all out a b
- ]
- load/all out
- ]
- ;inspired by tabbyCalc
- ;return is #"^M"
- sv: :system/view
- window: layout [
- backcolor black
- origin 5 space 5
- it: area "Please hit enter^/3e-6*5^^5+5+45+55654" black black 250x250 edge none font [name: "Tahoma" style: 'bold color: white]
- key escape [halt]
- ]
- it/feel: make object! bind/copy bind/copy [
- redraw: func [face act pos][
- if all [in face 'colors block? face/colors] [
- face/color: pick face/colors face <> focal-face
- ]
- ]
- detect: none
- over: none
- engage: func [face act event /local start end][
- switch act [
- down [
- either equal? face focal-face [unlight-text] [focus/no-show face]
- caret: offset-to-caret face event/offset
- show face
- ]
- over [
- if not-equal? caret offset-to-caret face event/offset [
- if not highlight-start [highlight-start: caret]
- highlight-end: caret: offset-to-caret face event/offset
- show face
- ]
- ]
- key [
- edit-text face event get in face 'action
- ;CHANGED BIT
- if event/key = #"^M" [
- end: find/reverse sv/caret newline
- start: any [
- find/reverse end newline
- head sv/caret
- ]
- string: copy/part start end
- ;If input is single number then do nothing.
- if all [
- attempt [load/all string]
- equal? 1 length? load/all string
- number? first load/all string
- ] [exit]
- attempt [caret: insert caret form do parse-math string]
- show face
- ]
- ]
- ]
- ]
- ] system/view ctx-text
- focus it
- view/new center-face window
- do-events
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement