Skip to content

Commit

Permalink
yeet, multi-line viewing support added
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 12, 2024
1 parent 4dad0a0 commit 53dbd14
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface EditorConfig {
screenRows: number;
screenCols: number;
numRows: number;
row: string;
row: string[];
}

enum EditorKey {
Expand Down Expand Up @@ -170,12 +170,22 @@ function getWindowSize() {
return { columns, rows };
}

function editorAppendRow(msg: string) {
const at = e.numRows;
e.row[at] = msg;
e.numRows++;
}

function editorOpen(filename: string) {
const data = Deno.readFileSync(filename);
const contents = decoder.decode(data).trimEnd();
const lines = contents.split("\n");

e.row = contents;
e.numRows++;
let i = 0;
while (i < lines.length) {
editorAppendRow(lines[i]);
i++;
}
}

function resetScreen() {
Expand All @@ -202,11 +212,7 @@ function editorDrawRows() {
abAppend("~");
}
} else {
let len = e.row.length;
if (len > e.screenCols) {
len = e.screenCols;
}
abAppend(e.row);
abAppend(e.row[y]);
}

abAppend("\x1b[K");
Expand Down Expand Up @@ -313,6 +319,7 @@ function initEditor() {
e.cursorX = 0;
e.cursorY = 0;
e.numRows = 0;
e.row = [];

const { columns, rows } = getWindowSize();
e.screenRows = rows;
Expand Down

0 comments on commit 53dbd14

Please sign in to comment.