#!/usr/bin/env julia module CalcApp # Global State gdisplaystr = "" gfisnumberentering = false gbinop = '+' gax = 0.0 gbx = 0.0 gfnotexit = true const MAX_DISPLAYSTR_LEN = 64 const RGB_RESULT = 6052991 const kbdstr = [ "Off" "C" "= 4 && idx <= 6) || (idx >= 8 && idx <= 10) || (idx >= 12 && idx <= 14) || idx == 16 || idx == 17 if gfisnumberentering if length(gdisplaystr) < MAX_DISPLAYSTR_LEN - 1 gdisplaystr *= label[1] end else gdisplaystr = string(label[1]) gfisnumberentering = true end displaystr(gdisplaystr, RGB_RESULT) elseif idx == 0 # Off myputs("O 0 0 0\n") gfnotexit = false elseif idx == 1 # Clear gdisplaystr = "" gfisnumberentering = false displaystr("0", RGB_RESULT) elseif idx == 2 # Backspace if length(gdisplaystr) > 0 gdisplaystr = gdisplaystr[1:end-1] displaystr(isempty(gdisplaystr) ? "0" : gdisplaystr, RGB_RESULT) end elseif idx == 18 # +/- if length(gdisplaystr) > 0 gdisplaystr = startswith(gdisplaystr, "-") ? gdisplaystr[2:end] : "-" * gdisplaystr displaystr(gdisplaystr, RGB_RESULT) end elseif idx in [3, 7, 11, 15] # Ops gbinop = label[1] gax = tryparse(Float64, gdisplaystr) !== nothing ? parse(Float64, gdisplaystr) : 0.0 gfisnumberentering = false elseif idx == 19 # Equals if gfisnumberentering gbx = tryparse(Float64, gdisplaystr) !== nothing ? parse(Float64, gdisplaystr) : 0.0 gfisnumberentering = false end if gbinop == '*' gax *= gbx elseif gbinop == '/' gax /= gbx elseif gbinop == '+' gax += gbx elseif gbinop == '-' gax -= gbx end gdisplaystr = string(gax) if endswith(gdisplaystr, ".0") gdisplaystr = gdisplaystr[1:end-2] end displaystr(gdisplaystr, RGB_RESULT) end end function main_logic() while gfnotexit line = readline(stdin) if isempty(line) && eof(stdin) break end trimmed = strip(line) if isempty(trimmed) continue end if trimmed == "drawapp" myputs("Fo 0 611 3\nFo 2 140 3\nF 0 16777215\nFR 0 0 0 10000 10000\nZ \nB 0 12632256\n") for r in 0:4, c in 0:3 myputs("F 0 10526880\nFR 0 $(c*2000+220) $(r*1200+1220) $(c*2000+2080) $(r*1200+2280)\n") myputs("F 0 986895\nR 0 $(c*2000+200) $(r*1200+1200) $(c*2000+2100) $(r*1200+2300)\n") myputs("F 0 $(kbdcolor[r+1, c+1])\nC\$ 0 $(c*2000+1100) $(r*1200+1700) \"$(kbdstr[r+1, c+1])\"\n") end myputs("F 0 255\nC\$ 0 5000 800 \"Julia cloud app\"\n") myputs("F 2 255\nC\$ 2 5000 7200 \"Corrie Zucker Technologies LLC.\"\nC\$ 2 5000 7340 \"d/b/a CZ Technologies\"\nZ \n") displaystr("0", RGB_RESULT) elseif trimmed == "QUERY_REMOTE" myputs("Rz 1200 900\n") else parts = split(trimmed) if length(parts) < 3 continue end button, x, y = parse(Int, parts[1]), parse(Int, parts[2]), parse(Int, parts[3]) selector = x < 0 ? x : button if selector == 1 # Mouse row, col = fld(y - 1200, 1200), fld(x - 200, 2000) if 0 <= row < 5 && 0 <= col < 4 key_to_exe(row, col) end elseif selector == -2 # Keyboard if button in [Int('o'), Int('O')] key_to_exe(0, 0) elseif button in [Int('c'), Int('C')] key_to_exe(0, 1) elseif button == 8 key_to_exe(0, 2) elseif button == Int('*') key_to_exe(0, 3) elseif button == Int('7') key_to_exe(1, 0) elseif button == Int('8') key_to_exe(1, 1) elseif button == Int('9') key_to_exe(1, 2) elseif button == Int('/') key_to_exe(1, 3) elseif button == Int('4') key_to_exe(2, 0) elseif button == Int('5') key_to_exe(2, 1) elseif button == Int('6') key_to_exe(2, 2) elseif button == Int('+') key_to_exe(2, 3) elseif button == Int('1') key_to_exe(3, 0) elseif button == Int('2') key_to_exe(3, 1) elseif button == Int('3') key_to_exe(3, 2) elseif button == Int('-') key_to_exe(3, 3) elseif button == Int('0') key_to_exe(4, 0) elseif button == Int('.') key_to_exe(4, 1) elseif button in [Int('I'), Int('i')] key_to_exe(4, 2) elseif button == Int('=') key_to_exe(4, 3) end elseif selector == -4 myputs("Rz $(button) $(y)\n") elseif selector == -5 myputs("Mv $(button) $(y)\n") elseif selector == -98 sleep((100 * y) / 1_000_000) end end end end # The "JIT/Script" entry point if abspath(PROGRAM_FILE) == @__FILE__ main_logic() end end # module using .CalcApp if abspath(PROGRAM_FILE) == @__FILE__ CalcApp.main_logic() end