/* 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 */
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;
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;
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);
}
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;
}
}
*(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) {
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;
}
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) {
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;
}