Advertisement
nicolas42

TabbyCalc

Nov 5th, 2012
3,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REBOL 2.53 KB | None | 0 0
  1. rebol [title: "TabbyCalc"]
  2.  
  3. title: "TabbyCalc"
  4.  
  5. ;it's old code. don't judge me!
  6.  
  7.  
  8. parse-math: funct [str] [
  9.  
  10.     parse-math-replace-list: [
  11.         "--" "+"
  12.         "+-" "-"
  13.         "*-" " * - "
  14.         "/-" " / - "
  15.         " e " "e"
  16.         " e- " "e-"
  17.         "^^" "** "
  18.     ]
  19.    
  20.     op: charset "*/+-^^()e<>="
  21.     ;e is an operation for exponents, eg 4e-2.
  22.     ;consequently e cannot be a variable
  23.    
  24.     nop: complement op
  25.     out: copy []
  26.     a: none
  27.     parse str [
  28.         some [
  29.             copy a some nop (append out a)
  30.             | copy a some op (append out a)
  31.         ]
  32.         end
  33.     ]
  34.     out: form out
  35.     foreach [a b] parse-math-replace-list [
  36.         replace/all out a b
  37.     ]
  38.     load/all out
  39. ]
  40.  
  41. ;inspired by tabbyCalc
  42. ;return is #"^M"
  43.  
  44. sv: :system/view
  45.  
  46. window: layout [
  47.     backcolor black
  48.     origin 5 space 5
  49.     it: area "Please hit enter^/3e-6*5^^5+5+45+55654" black black 250x250 edge none font [name: "Tahoma" style: 'bold color: white]
  50.     key escape [halt]
  51. ]
  52.  
  53. it/feel: make object! bind/copy bind/copy [
  54.     redraw: func [face act pos][
  55.         if all [in face 'colors block? face/colors] [
  56.             face/color: pick face/colors face <> focal-face
  57.         ]
  58.     ]
  59.     detect: none
  60.     over: none
  61.     engage: func [face act event /local start end][
  62.         switch act [
  63.             down [
  64.                 either equal? face focal-face [unlight-text] [focus/no-show face]
  65.                 caret: offset-to-caret face event/offset
  66.                 show face
  67.             ]
  68.             over [
  69.                 if not-equal? caret offset-to-caret face event/offset [
  70.                     if not highlight-start [highlight-start: caret]
  71.                     highlight-end: caret: offset-to-caret face event/offset
  72.                     show face
  73.                 ]
  74.             ]
  75.             key [
  76.                 edit-text face event get in face 'action
  77.                
  78.                 ;CHANGED BIT
  79.                 if event/key = #"^M" [
  80.                
  81.                     end: find/reverse sv/caret newline
  82.                     start: any [
  83.                         find/reverse end newline
  84.                         head sv/caret
  85.                     ]
  86.                     string: copy/part start end
  87.            
  88.                     ;If input is single number then do nothing.
  89.                     if all [
  90.                         attempt [load/all string]
  91.                         equal? 1 length? load/all string
  92.                         number? first load/all string
  93.                     ] [exit]
  94.  
  95.                     attempt [caret: insert caret form do parse-math string]
  96.                     show face
  97.                 ]
  98.             ]
  99.         ]
  100.     ]
  101. ] system/view ctx-text
  102.  
  103. focus it
  104. view/new center-face window
  105. do-events
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement