very basic code editing!

This commit is contained in:
dylan
2023-05-05 11:52:08 -07:00
parent 6b90d883e9
commit 1e91232bd6
9 changed files with 233 additions and 22 deletions

View File

@ -3,6 +3,7 @@ import { getKeysPressed, shiftKeyDown, shiftMap, K } from "./keyboard.ts";
import { font } from "./font.ts";
import { addToContext, evalCode } from "./runcode.ts";
import { clearScreen, fillRect } from "./window.ts";
import { COLOR } from "./colors.ts";
const lineHeight = 6;
@ -41,6 +42,7 @@ addToContext("print", print);
addToContext("printVal", printVal);
const update = () => {
// TODO: model this after the newer editmode.ts version using getKeyboardString
for (const key of getKeysPressed()) {
let char = String.fromCharCode(key).toLowerCase();
if (shiftKeyDown()) {
@ -108,7 +110,7 @@ const update = () => {
const drawTextAbove = () => {
textLinesAbove.forEach((line, i) => {
fillRect(0, 1+i*lineHeight, 4*(line.length+1)+1, lineHeight+1, 0);
fillRect(0, 1+i*lineHeight, 4*(line.length+1)+1, lineHeight+1, COLOR.BLACK);
drawText(-1, 1+i*lineHeight, line);
});
}
@ -118,8 +120,8 @@ const draw = () => {
drawTextAbove();
fillRect(0, 1+textLinesAbove.length*lineHeight, 4*(2+maxLineLen+1)+1, lineHeight+1, 0);
fillRect((2+index)*4, textLinesAbove.length*lineHeight+1, 4, lineHeight-1, 3);
fillRect(0, 1+textLinesAbove.length*lineHeight, 4*(2+maxLineLen+1)+1, lineHeight+1, COLOR.BLACK);
fillRect((2+index)*4, textLinesAbove.length*lineHeight+1, 4, lineHeight-1, COLOR.RED);
drawText(-1, 1+textLinesAbove.length*lineHeight, "> "+currentLine);
}