]> git.mdlowis.com Git - projs/tide.git/commitdiff
added content to status bar for tracking charset, modified state of buffer and path...
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 9 Oct 2016 01:13:20 +0000 (21:13 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 9 Oct 2016 01:13:20 +0000 (21:13 -0400)
buf.c
edit.h
screen.c
xedit.c

diff --git a/buf.c b/buf.c
index 606d0f5514086d2b5c98f28306d2accedcb20d2a..b9425c3eab94822223550af34a89687cc728e723 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -81,6 +81,7 @@ void buf_load(Buf* buf, char* path) {
         funmap(file);
     }
     buf->insert_mode = false;
+    buf->modified    = false;
 }
 
 void buf_save(Buf* buf) {
@@ -92,6 +93,7 @@ void buf_save(Buf* buf) {
     else
         utf8save(buf, file);
     fclose(file);
+    buf->modified = false;
 }
 
 void buf_resize(Buf* buf, size_t sz) {
@@ -130,11 +132,12 @@ static void syncgap(Buf* buf, unsigned off) {
 
 void buf_init(Buf* buf) {
     buf->insert_mode = false;
-    buf->bufsize  = BufSize;
-    buf->bufstart = (Rune*)malloc(buf->bufsize * sizeof(Rune));
-    buf->bufend   = buf->bufstart + buf->bufsize;
-    buf->gapstart = buf->bufstart;
-    buf->gapend   = buf->bufend;
+    buf->modified    = false;
+    buf->bufsize     = BufSize;
+    buf->bufstart    = (Rune*)malloc(buf->bufsize * sizeof(Rune));
+    buf->bufend      = buf->bufstart + buf->bufsize;
+    buf->gapstart    = buf->bufstart;
+    buf->gapend      = buf->bufend;
 }
 
 void buf_clr(Buf* buf) {
@@ -144,12 +147,14 @@ void buf_clr(Buf* buf) {
 
 void buf_del(Buf* buf, unsigned off) {
     if (!buf->insert_mode) { return; }
+    buf->modified = true;
     syncgap(buf, off);
     buf->gapend++;
 }
 
 void buf_ins(Buf* buf, unsigned off, Rune rune) {
     if (!buf->insert_mode) { return; }
+    buf->modified = true;
     syncgap(buf, off);
     *(buf->gapstart++) = rune;
 }
diff --git a/edit.h b/edit.h
index fcda730efb7e4995d4961f5050aabd60e812de17..876b876d6faed0387732b44e18f07b5698e3b5bf 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -2,6 +2,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdbool.h>
+#include <stdarg.h>
 #include <string.h>
 
 /* Charset Handling
@@ -32,7 +33,6 @@ bool utf8decode(Rune* rune, size_t* length, int byte);
 Rune fgetrune(FILE* f);
 void fputrune(Rune rune, FILE* f);
 
-
 /* Input Handling
  *****************************************************************************/
 /* key definitions */
@@ -135,6 +135,7 @@ typedef struct buf {
     char* path;       /* the path to the open file */
     int charset;      /* the character set of the buffer */
     bool insert_mode; /* tracks current mode */
+    bool modified;    /* tracks whether the buffer has been modified */
     size_t bufsize;   /* size of the buffer in runes */
     Rune* bufstart;   /* start of the data buffer */
     Rune* bufend;     /* end of the data buffer */
@@ -175,6 +176,7 @@ void screen_clearrow(unsigned row);
 void screen_setrowoff(unsigned row, unsigned off);
 unsigned screen_setcell(unsigned row, unsigned col, Rune r);
 Rune screen_getcell(unsigned row, unsigned col);
+void screen_status(char* fmt, ...);
 
 /* Miscellaneous Functions
  *****************************************************************************/
@@ -182,7 +184,6 @@ void die(char* msg);
 
 /* Color Scheme Handling
  *****************************************************************************/
-
 /* color indexes for the colorscheme */
 enum ColorId {
     CLR_BASE03 = 0,
index eb74f5d10e40c221e8b84e90b4092d030d3b01d4..55cee78fbf3809269f016c9fcfba80ac70d277b6 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -6,7 +6,6 @@ static Row** Rows;
 
 void screen_reflow(Buf* buf) {
     unsigned pos = Rows[1]->off;
-    screen_clearrow(0);
     for (unsigned y = 1; y < NumRows; y++) {
         screen_clearrow(y);
         screen_setrowoff(y, pos);
@@ -120,7 +119,6 @@ static void fill_row(Buf* buf, unsigned row, unsigned pos) {
 static unsigned prev_screen_line(Buf* buf, unsigned bol, unsigned off) {
     unsigned pos = bol;
     while (true) {
-        //printf("bol: %u, pos: %u, off: %u\n", bol, pos, off);
         unsigned x = 0;
         for (; x < NumCols && (pos + x) < off; x++) {
             Rune r = buf_get(buf, pos+x);
@@ -196,3 +194,17 @@ void screen_update(Buf* buf, unsigned csr, unsigned* csrx, unsigned* csry) {
         }
     }
 }
+
+void screen_status(char* fmt, ...) {
+    char buffer[NumCols+1];
+    memset(buffer, 0, NumCols+1);
+    va_list args;
+    va_start(args, fmt);
+    vsnprintf(buffer, NumCols, fmt, args);
+    va_end(args);
+    screen_clearrow(0);
+    Rows[0]->len  = NumCols;
+    Rows[0]->rlen = NumCols;
+    for (unsigned i = 0; buffer[i] && i < NumCols; i++)
+        Rows[0]->cols[i] = (Rune)buffer[i];
+}
diff --git a/xedit.c b/xedit.c
index afd2d27247eff0ac378b1fb967e8bd726eadda6e..0cf00bdf1d86e74c8713402a016e32f0deaa3312 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -200,11 +200,12 @@ static void redraw(void) {
     XftColor bkgclr = xftcolor(CLR_BASE03);
     XftColor gtrclr = xftcolor(CLR_BASE02);
     XftColor csrclr = xftcolor(CLR_BASE3);
+    XftColor staclr = xftcolor(CLR_BASE2);
     XftColor txtclr = xftcolor(CLR_BASE0);
 
     /* draw the background colors */
     XftDrawRect(X.xft, &bkgclr, 0, 0, X.width, X.height);
-    XftDrawRect(X.xft, &gtrclr, 0, 0, X.width, fheight);
+    XftDrawRect(X.xft, &gtrclr, 0, 0, X.width, fheight + X.font->descent);
     XftDrawRect(X.xft, &gtrclr, 79 * fwidth, 0, fwidth, X.height);
 
     /* update the screen buffer and retrieve cursor coordinates */
@@ -214,9 +215,13 @@ static void redraw(void) {
     /* flush the screen buffer */
     unsigned nrows, ncols;
     screen_getsize(&nrows, &ncols);
+    screen_status("[%s]%s%s",
+        (Buffer.charset == BINARY ? "BIN" : "UTF-8"),
+        (Buffer.modified ? " * " : " "),
+        Buffer.path);
     for (unsigned y = 0; y < nrows; y++) {
         Row* row = screen_getrow(y);
-        XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
+        XftDrawString32(X.xft, (y==0 ? &staclr : &txtclr), X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
     }
 
     /* Place cursor on screen */