Skip to content

Commit

Permalink
statusbar work
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 13, 2024
1 parent 078b8ef commit 647fa70
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface EditorConfig {
numRows: number;
row: string[];
render: string[];
filename: string;
}

enum EditorKey {
Expand Down Expand Up @@ -218,6 +219,7 @@ function editorAppendRow(msg: string) {
}

function editorOpen(filename: string) {
e.filename = filename;
const data = Deno.readFileSync(filename);
const contents = decoder.decode(data).replaceAll("\r", "").trimEnd();
const lines = contents.split("\n");
Expand Down Expand Up @@ -283,20 +285,40 @@ function editorDrawRows() {
}
}

if (y < e.screenRows - 1) {
abAppend("\r\n");
}
abAppend("\r\n");
y++;
}
}

function editorDrawStatusBar() {
abAppend("\x1b[7m");

const status = `${e.filename != "" ? e.filename : "[No Name]"} - ${e.numRows} lines`;
abAppend(status);

const rStatus = `${e.cursorY + 1}/${e.numRows}`;

let len = status.length;
while (len < e.screenCols) {
if (e.screenCols - len == rStatus.length) {
abAppend(rStatus);
break;
} else {
abAppend(" ");
len++;
}
}
abAppend("\x1b[m");
}

function editorRefreshScreen() {
editorScroll();

abAppend("\x1b[?25l");
abAppend("\x1b[H");

editorDrawRows();
editorDrawStatusBar();

const yPos = `${(e.cursorY - e.rowOffset) + 1}`;
const xPos = `${(e.renderX - e.colOffset) + 1}`;
Expand Down Expand Up @@ -417,9 +439,10 @@ function initEditor() {
e.numRows = 0;
e.row = [];
e.render = [];
e.filename = "";

const { columns, rows } = getWindowSize();
e.screenRows = rows;
e.screenRows = rows - 1;
e.screenCols = columns;
}

Expand Down

0 comments on commit 647fa70

Please sign in to comment.