Show caret, backspace, and left-right arrows
This commit is contained in:
parent
99a8c500c7
commit
7de521bd39
@ -54,10 +54,15 @@ const drawText = (x: number, y: number, text: string) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const drawRect = (x: number, y: number, w: number, h: number, color: number) => {
|
||||||
|
setPixelsInRect(x, y, w, Array(w*h).fill(color));
|
||||||
|
}
|
||||||
|
|
||||||
const faux = {
|
const faux = {
|
||||||
clear_screen: clearScreen,
|
clear_screen: clearScreen,
|
||||||
draw_sprite: drawSprite,
|
draw_sprite: drawSprite,
|
||||||
draw_text: drawText,
|
draw_text: drawText,
|
||||||
|
draw_rect: drawRect,
|
||||||
key_down: keyDown,
|
key_down: keyDown,
|
||||||
key_pressed: keyPressed,
|
key_pressed: keyPressed,
|
||||||
key_released: keyReleased,
|
key_released: keyReleased,
|
||||||
|
@ -5,11 +5,16 @@ export const K = {
|
|||||||
ENTER: 257,
|
ENTER: 257,
|
||||||
TAB: 258,
|
TAB: 258,
|
||||||
BACKSPACE: 259,
|
BACKSPACE: 259,
|
||||||
|
INSERT: 260,
|
||||||
DELETE: 261,
|
DELETE: 261,
|
||||||
ARROW_RIGHT: 262,
|
ARROW_RIGHT: 262,
|
||||||
ARROW_LEFT: 263,
|
ARROW_LEFT: 263,
|
||||||
ARROW_DOWN: 264,
|
ARROW_DOWN: 264,
|
||||||
ARROW_UP: 265,
|
ARROW_UP: 265,
|
||||||
|
PAGE_UP: 266,
|
||||||
|
PAGE_DOWN: 267,
|
||||||
|
HOME: 268,
|
||||||
|
END: 269,
|
||||||
CAPS_LOCK: 280,
|
CAPS_LOCK: 280,
|
||||||
F1: 290,
|
F1: 290,
|
||||||
F2: 291,
|
F2: 291,
|
||||||
|
23
repl.ts
23
repl.ts
@ -1,8 +1,9 @@
|
|||||||
import faux from "./builtins.ts";
|
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";
|
import { font } from "./font.ts";
|
||||||
|
|
||||||
let line = "";
|
let line = "";
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
for (const key of getKeysPressed()) {
|
for (const key of getKeysPressed()) {
|
||||||
@ -15,13 +16,31 @@ const update = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (char in font) {
|
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 = () => {
|
const draw = () => {
|
||||||
faux.clear_screen();
|
faux.clear_screen();
|
||||||
|
faux.draw_rect((2+index)*4, 0, 5, 6, 3);
|
||||||
faux.draw_text(0, 0, "> "+line);
|
faux.draw_text(0, 0, "> "+line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user