]> git.mdlowis.com Git - projs/tide.git/commitdiff
added colors to status box
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 11 May 2018 03:03:04 +0000 (23:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 11 May 2018 03:03:04 +0000 (23:03 -0400)
inc/edit.h
lib/buf.c
lib/x11.c

index 29db7d52632161ac946a755648fc6bf4c3c63ddc..ce7a424663fec58864dc8642a33bcac3e3a0ba09 100644 (file)
@@ -17,6 +17,9 @@ typedef struct {
 
 /* gap buffer main data structure */
 typedef struct {
+    enum {
+        NORMAL = 0, MODIFIED, OUTDATED, ERRORED
+    } status;
     char* path;       /* the path to the open file */
     uint64_t modtime; /* modification time of the opened file */
     size_t bufsize;   /* size of the buffer in runes */
@@ -26,7 +29,6 @@ typedef struct {
     char* gapend;     /* end of the gap */
     Log* undo;        /* undo list */
     Log* redo;        /* redo list */
-    bool modified;    /* tracks whether the buffer has been modified */
     Sel selection;    /* the currently selected text */
 } Buf;
 
index c6a2c7b9ca985d6e702b5ae49d06fdc5076570d6..57ae90020188b4bfc2e874be0341ca38d79bb71b 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -24,7 +24,7 @@ void buf_init(Buf* buf) {
         buf_logclear(buf);
     }
     /* reset the state to defaults */
-    buf->modified  = false;
+    buf->status    = NORMAL;
     buf->bufsize   = 8192;
     buf->bufstart  = malloc(buf->bufsize);
     buf->bufend    = buf->bufstart + buf->bufsize;
@@ -61,8 +61,8 @@ void buf_load(Buf* buf, char* path) {
     if (fd > 0) close(fd);
 
     /* reset buffer state */
-    buf->modified = false;
-    buf->modtime  = (uint64_t)sb.st_mtime;
+    buf->status  = NORMAL;
+    buf->modtime = (uint64_t)sb.st_mtime;
     buf_logclear(buf);
 }
 
@@ -87,12 +87,9 @@ void buf_save(Buf* buf) {
             wptr += nwrite, towrite -= nwrite;
         close(fd);
         /* report success or failure */
-        if (nwrite >= 0)
-            buf->modified = false;
-        //else
-        //    buf->errfn("Failed to write file");
+        buf->status = (nwrite >= 0 ? NORMAL : ERRORED);
     } else {
-        //buf->errfn("Need a filename: SaveAs ");
+        buf->status = ERRORED;
     }
 }
 
@@ -150,6 +147,7 @@ static void putb(Buf* buf, char b, Sel* p_sel) {
     *(buf->gapstart++) = b;
     p_sel->end = p_sel->end + 1u;
     p_sel->beg = p_sel->end;
+    buf->status = MODIFIED;
 }
 
 static char getb(Buf* buf, size_t off) {
@@ -197,6 +195,7 @@ void buf_del(Buf* buf) {
     Sel sel = getsel(buf);
     size_t nbytes = sel.end - sel.beg;
     if (nbytes > 0) {
+        buf->status = MODIFIED;
         //char* str = buf_gets(buf, &sel);
         syncgap(buf, sel.beg);
         buf->gapend += nbytes;
index e2613b52a36ce6a216a9b36e928b0ebf466284a5..2a4a1d7902769030496cec3c3cbd87dce07d8f74 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -275,10 +275,12 @@ static void draw_rect(int color, int x, int y, int width, int height) {
 }
 
 static void draw_statbox(drawcsr* csr) {
-    View* view = win_view(EDIT);
-    int statclr = Orange; //(view->buffer.modified ? Purple : TagsBg);
     draw_rect(VerBdr, ScrollWidth, 0, 1, X.height/4);
-    draw_rect(statclr, 0, 0, ScrollWidth, X.height/4);
+    switch (win_view(EDIT)->buffer.status) {
+        case NORMAL:   draw_rect(TagsBg, 0, 0, ScrollWidth, X.height/4); break;
+        case MODIFIED: draw_rect(Purple, 0, 0, ScrollWidth, X.height/4); break;
+        case ERRORED:  draw_rect(Red, 0, 0, ScrollWidth, X.height/4);    break;
+    }
 }
 
 static void draw_view(int i, size_t nrows, drawcsr* csr, int bg, int fg, int sel) {
@@ -560,7 +562,7 @@ void win_loop(void) {
 
 void win_quit(void) {
     static uint64_t before = 0;
-    if (!win_buf(EDIT)->modified || (X.now - before) <= (uint64_t)ClickTime)
+    if ((win_buf(EDIT)->status != MODIFIED) || (X.now - before) <= (uint64_t)ClickTime)
         exit(0);
     before = X.now;
 }