Show caret, backspace, and left-right arrows

This commit is contained in:
dylan
2023-05-03 13:44:28 -07:00
parent 99a8c500c7
commit 7de521bd39
3 changed files with 31 additions and 2 deletions

23
repl.ts
View File

@ -1,8 +1,9 @@
import faux from "./builtins.ts";
import { getKeysPressed, shiftKeyDown, shiftMap } from "./keyboard.ts";
import { getKeysPressed, shiftKeyDown, shiftMap, K } from "./keyboard.ts";
import { font } from "./font.ts";
let line = "";
let index = 0;
const update = () => {
for (const key of getKeysPressed()) {
@ -15,13 +16,31 @@ const update = () => {
}
}
if (char in font) {
line += char;
line = line.slice(0, index)+char+line.slice(index);
index += 1;
} else if (key === K.BACKSPACE) {
line = line.slice(0, -1);
index -= 1;
if (index < 0) {
index = 0;
}
} else if (key === K.ARROW_LEFT) {
index -= 1;
if (index < 0) {
index = 0;
}
} else if (key === K.ARROW_RIGHT) {
index += 1;
if (index > line.length) {
index = line.length;
}
}
}
}
const draw = () => {
faux.clear_screen();
faux.draw_rect((2+index)*4, 0, 5, 6, 3);
faux.draw_text(0, 0, "> "+line);
}