funmap(file);
}
buf->insert_mode = false;
+ buf->modified = false;
}
void buf_save(Buf* buf) {
else
utf8save(buf, file);
fclose(file);
+ buf->modified = false;
}
void buf_resize(Buf* buf, size_t sz) {
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) {
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;
}
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
+#include <stdarg.h>
#include <string.h>
/* Charset Handling
Rune fgetrune(FILE* f);
void fputrune(Rune rune, FILE* f);
-
/* Input Handling
*****************************************************************************/
/* key definitions */
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 */
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
*****************************************************************************/
/* Color Scheme Handling
*****************************************************************************/
-
/* color indexes for the colorscheme */
enum ColorId {
CLR_BASE03 = 0,
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);
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);
}
}
}
+
+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];
+}
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 */
/* 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 */