Skip to content

Commit

Permalink
add message bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kjloveless committed Nov 13, 2024
1 parent 647fa70 commit 3812308
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface EditorConfig {
row: string[];
render: string[];
filename: string;
statusMsg: string;
statusMsgTime: Date;
}

enum EditorKey {
Expand Down Expand Up @@ -309,6 +311,14 @@ function editorDrawStatusBar() {
}
}
abAppend("\x1b[m");
abAppend("\r\n");
}

function editorDrawMessageBar() {
abAppend("\x1b[K");
if ((e.statusMsg.length > 0) && ((Date.now() - e.statusMsgTime) < 5000)) {
abAppend(e.statusMsg);
}
}

function editorRefreshScreen() {
Expand All @@ -319,6 +329,7 @@ function editorRefreshScreen() {

editorDrawRows();
editorDrawStatusBar();
editorDrawMessageBar();

const yPos = `${(e.cursorY - e.rowOffset) + 1}`;
const xPos = `${(e.renderX - e.colOffset) + 1}`;
Expand All @@ -331,6 +342,11 @@ function editorRefreshScreen() {
abFree();
}

function editorSetStatusMessage(msg: string) {
e.statusMsg = msg;
e.statusMsgTime = new Date();
}

function editorMoveCursor(key: string | number) {
let row = (e.cursorY >= e.numRows) ? undefined : e.row[e.cursorY];
switch (key) {
Expand Down Expand Up @@ -440,9 +456,10 @@ function initEditor() {
e.row = [];
e.render = [];
e.filename = "";
e.statusMsg = "";

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

Expand All @@ -453,6 +470,8 @@ if (import.meta.main) {
editorOpen(Deno.args[0]);
}

editorSetStatusMessage("HELP: Ctrl-Q = quit");

while(true) {
editorRefreshScreen();
editorProcessKeypress();
Expand Down

0 comments on commit 3812308

Please sign in to comment.