# calc.cr module CloudCalc extend self # Global-like state using class variables @@gfisnum = false @@gfnotexit = true @@gdisplaystr = "" @@gbinop = "+" @@gax = 0.0 @@gbx = 1.0 MAX_DISP = 24 # Enforce strict line buffering STDOUT.flush_on_newline = true KBD = [ {"Off", 2628095}, {"C", 2628095}, {" 0 displaystr("0", 6052991) if @@gdisplaystr.size == 1 @@gdisplaystr = @@gdisplaystr[0...-1] displaystr(@@gdisplaystr, 6052991) if @@gdisplaystr.size > 0 end when 18 if @@gdisplaystr.size > 0 if @@gdisplaystr.starts_with?("-") @@gdisplaystr = @@gdisplaystr[1..-1] elsif @@gdisplaystr.size < (MAX_DISP - 1) @@gdisplaystr = "-" + @@gdisplaystr end displaystr(@@gdisplaystr, 6052991) end when 3, 7, 11, 15 @@gbinop = KBD[rowcol][0] @@gax = @@gdisplaystr.to_f @@gfisnum = false when 19 if @@gfisnum @@gbx = @@gdisplaystr.to_f @@gfisnum = false end case @@gbinop when "*" then @@gax *= @@gbx when "/" then @@gax /= @@gbx when "+" then @@gax += @@gbx when "-" then @@gax -= @@gbx end @@gdisplaystr = @@gax.to_s displaystr(@@gdisplaystr, 6052991) end end def run while @@gfnotexit line = gets break unless line # Fix: Use .strip to handle "drawapp" regardless of \n or \r\n if line.strip == "drawapp" puts "Fo 0 611 3\nFo 2 140 3\nF 0 16777215\nFR 0 0 0 10000 10000\nB 0 12632256" displaystr("0", 6052991) KBD.each_with_index do |(label, color), i| row, col = i // 4, i % 4 puts "F 0 10526880\nFR 0 #{(col*2000+220)} #{(row*1200+1220)} #{(col*2000+2080)} #{(row*1200+2280)}" puts "F 0 986895\nR 0 #{(col*2000+200)} #{(row*1200+1200)} #{(col*2000+2100)} #{(row*1200+2300)}" puts "F 0 #{color}\nC$ 0 #{(col*2000+1100)} #{(row*1200+1700)}\"#{label}\"" end puts "F 0 16711935\nC$ 0 5000 800 \"Crystal cloud app\"\nF 2 255" puts "C$ 2 5000 7200\"Corrie Zucker Technologies LLC.\"\nC$ 2 5000 7340\"d/b/a CZ Technologies\"\nZ " else # Fix: Extract the actual string match [0] from MatchData before to_i nums = line.scan(/-?\d+/).map { |m| m[0].to_i } if nums.size >= 3 button, x, y = nums[0], nums[1], nums[2] if x >= 0 row, col = (y - 1200) // 1200, (x - 200) // 2000 keytoexe(row * 4 + col) if row >= 0 && row < 5 && col >= 0 && col < 4 elsif x == -2 keymap = {79=>0, 111=>0, 99=>1, 67=>1, 8=>2, 42=>3, 55=>4, 56=>5, 57=>6, 47=>7, 52=>8, 53=>9, 54=>10, 43=>11, 49=>12, 50=>13, 51=>14, 45=>15, 48=>16, 46=>17, 105=>18, 73=>18, 61=>19} keytoexe(keymap[button]) if keymap.has_key?(button) elsif x == -4 puts "Rz #{(button)} #{(y)}" elsif x == -5 puts "Mv #{(button)} #{(y)}" elsif x == -98 # Warning fix from before sleep (0.0013 * y).seconds end end end end end end CloudCalc.run