From: Michael D. Lowis Date: Sun, 9 Oct 2016 01:13:20 +0000 (-0400) Subject: added content to status bar for tracking charset, modified state of buffer and path... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=aa60290e8f9b83278b92228c1cf1023a89b158be;p=projs%2Ftide.git added content to status bar for tracking charset, modified state of buffer and path to the file --- diff --git a/buf.c b/buf.c index 606d0f5..b9425c3 100644 --- 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 fcda730..876b876 100644 --- a/edit.h +++ b/edit.h @@ -2,6 +2,7 @@ #include #include #include +#include #include /* 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, diff --git a/screen.c b/screen.c index eb74f5d..55cee78 100644 --- 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 afd2d27..0cf00bd 100644 --- 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, >rclr, 0, 0, X.width, fheight); + XftDrawRect(X.xft, >rclr, 0, 0, X.width, fheight + X.font->descent); XftDrawRect(X.xft, >rclr, 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 */