import * as readline from 'readline'; let gfisnum: boolean = false; let gdisplaystr: string = ""; let gbinop: string = "+"; let gax: string = "0"; let gbx: string = "1"; const MAXDISP: number = 24; const kbdstring: string[] = ["Off", "C", " 0) { gdisplaystr = gdisplaystr.slice(0, -1); displaystr(gdisplaystr === "" ? "0" : gdisplaystr, 6052991); } } else if (rowcol === 18) { if (gdisplaystr.length > 0) { if (gdisplaystr.startsWith("-")) { gdisplaystr = gdisplaystr.substring(1); } else if (gdisplaystr.length < (MAXDISP - 1)) { gdisplaystr = "-" + gdisplaystr; } displaystr(gdisplaystr, 6052991); } } else if (opKeys.includes(rowcol)) { gbinop = kbdstring[rowcol]; gax = gdisplaystr || "0"; gfisnum = false; } else if (rowcol === 19) { if (gfisnum) { gbx = gdisplaystr; gfisnum = false; } let res = 0; const a = parseFloat(gax); const b = parseFloat(gbx); switch (gbinop) { case "+": res = a + b; break; case "-": res = a - b; break; case "*": res = a * b; break; case "/": res = a / b; break; } gax = res.toString(); gdisplaystr = gax; displaystr(gdisplaystr, 6052991); } } const rl = readline.createInterface({ input: process.stdin, terminal: false }); rl.on('line', (line: string) => { if (line === "drawapp") { myputs("Fo 0 611 3\nFo 1 380 3\nFo 2 140 3\nF 0 16777215\nFR 0 0 0 10000 10000\nZ \nB 0 12632256\n"); for (let i = 0; i < kbdstring.length; i++) { const r = Math.floor(i / 4); const c = i % 4; 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[i]}\nC$ 0 ${c * 2000 + 1100} ${r * 1200 + 1700} "${kbdstring[i]}"\n`); } myputs(`F 1 16711935\nL$ 1 20 900 "typescript cloud app"\nZ \nF 2 255\nC$ 2 5000 7200 "Corrie Zucker Technologies LLC."\nC$ 2 5000 7340 "d/b/a CZ Technologies"\nZ \n`); displaystr("0", 6052991); } else if (line === "QUERY_REMOTE") { myputs("Rz 1200 900\n"); } else { const parts = line.split(" "); const btn = parseInt(parts[0]); const x = parseInt(parts[1]); const y = parseInt(parts[2]); if (x >= 0) { const row = Math.floor((y - 1200) / 1200); const col = Math.floor((x - 200) / 2000); if (row >= 0 && row < 5 && col >= 0 && col < 4) { keytoexe(row * 4 + col); } } else if (x === -2) { const char = String.fromCharCode(btn).toUpperCase(); const map: Record = { 'O': 0, 'C': 1, '*': 3, '/': 7, '+': 11, '-': 15, '.': 17, 'I': 18, '=': 19 }; if (btn === 8) keytoexe(2); else if (char >= '0' && char <= '9') { const lookup: Record = {'7':4,'8':5,'9':6,'4':8,'5':9,'6':10,'1':12,'2':13,'3':14,'0':16}; keytoexe(lookup[char]); } else if (map[char] !== undefined) { keytoexe(map[char]); } } else if (x === -4) { myputs(`Rz ${btn} ${y}\n`); } else if (x === -5) { myputs(`Mv ${btn} ${y}\n`); } } });