Show caret, backspace, and left-right arrows
This commit is contained in:
23
repl.ts
23
repl.ts
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user