diff --git a/apps/pound.c b/apps/pound.c index affc83ba..adcdaaa1 100644 --- a/apps/pound.c +++ b/apps/pound.c @@ -27,6 +27,7 @@ struct editorConfig { unsigned int numrows; unsigned int rowsroom; struct erow *row; + bool dirty; } E; #define STYLE_NORMAL 0 @@ -143,7 +144,7 @@ void editorSave(void) { if (cpm_open_file(&cpm_fcb)) { editorDrawStatusMsg("Saving to new file..."); if (write_file(&cpm_fcb)) editorDrawStatusMsg("Failed to save file"); - return; + goto success; } editorDrawStatusMsg("Saving to temporary file..."); @@ -169,7 +170,9 @@ void editorSave(void) { return; } +success: editorDrawStatusMsg("File saved"); + E.dirty = false; } char line[256]; @@ -231,22 +234,23 @@ void editorScroll() { } } +static const char *const dirty_string = " (modified)"; + void editorDrawStatusBar() { - uint8_t x, p; + uint8_t x, y, p; screen_setcursor(0, E.screenrows); screen_setstyle(STYLE_REVERSE); - x = p = 0; + p = 0; while (p<11) { if (cpm_fcb.f[p] != ' ') { screen_putchar(cpm_fcb.f[p]); - x++; } p++; - if (p == 8) { - screen_putchar('.'); - x++; - } + if (p == 8) screen_putchar('.'); } + for (p = 0; E.dirty && p= ' ' && c <= '~') editorInsertChar(c); + if (c >= ' ' && c <= '~') { + editorInsertChar(c); + if (!E.dirty) { + E.dirty = true; + editorDrawStatusBar(); + } + } break; } } @@ -419,6 +430,7 @@ void initEditor(void) { E.screenrows--; // two lines for status bar and status message E.cx = E.cy = E.rowoff = E.coloff = E.numrows = E.rowsroom = 0; E.row = NULL; + E.dirty = false; } // -------------------- MAIN --------------------