Skip to content

Commit

Permalink
start writing chars to screen, yes ik theres a bug, relax
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 13, 2024
1 parent 99207f2 commit b5c4272
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function abFree() {

function exit(msg: string, code: number = 0) {
resetScreen();

console.log(`${bytesWritten} bytes written this session!\r\n${msg}\r\n`);

// TODO: fix how bytes are being accumulated
// console.log(`${bytesWritten} bytes written this session!\r\n${msg}\r\n`);
console.log(`${msg}\r\n`);

Deno.stdin.close();
Deno.stdout.close();
Expand Down Expand Up @@ -205,6 +207,21 @@ function editorAppendRow(msg: string) {
e.numRows++;
}

function editorRowInsertChar(row: number, at: number, char: string) {
if (at < 0 || at > e.row[row].length) at = e.row[row].length;

e.row[row] = e.row[row].substring(0, at) + char + e.row[row].substring(at + 1);
editorUpdateRow(row);
}

function editorInsertChar(char: string) {
if (e.cursorY == e.numRows) {
editorAppendRow("");
}
editorRowInsertChar(e.cursorY, e.cursorX, char);
e.cursorX++;
}

function editorOpen(filename: string) {
console.log(`filename: ${filename}`);
e.filename = filename;
Expand Down Expand Up @@ -420,6 +437,10 @@ function editorProcessKeypress() {
case EditorKey.ARROW_RIGHT:
editorMoveCursor(char);
break;

default:
editorInsertChar(String.fromCharCode(char));
break;
}
}

Expand Down

0 comments on commit b5c4272

Please sign in to comment.