static Row** Rows;
static void screen_reflow(Buf* buf) {
- unsigned pos = Rows[1]->off;
- for (unsigned y = 1; y < NumRows; y++) {
+ unsigned pos = Rows[0]->off;
+ for (unsigned y = 0; y < NumRows; y++) {
screen_clearrow(y);
screen_getrow(y)->off = pos;
for (unsigned x = 0; x < NumCols;) {
prevln = prev_screen_line(buf, prevln, first);
/* delete the last row and shift the others */
free(Rows[NumRows - 1]);
- memmove(&Rows[2], &Rows[1], sizeof(Row*) * (NumRows-2));
- Rows[1] = calloc(1, sizeof(Row) + (NumCols * sizeof(UGlyph)));
- Rows[1]->off = prevln;
+ memmove(&Rows[1], &Rows[0], sizeof(Row*) * (NumRows-1));
+ Rows[0] = calloc(1, sizeof(Row) + (NumCols * sizeof(UGlyph)));
+ Rows[0]->off = prevln;
/* fill in row content */
- fill_row(buf, 1, Rows[1]->off);
- first = Rows[1]->off;
+ fill_row(buf, 0, Rows[0]->off);
+ first = Rows[0]->off;
}
}
static void scroll_dn(Buf* buf, unsigned csr, unsigned last) {
while (csr > last) {
/* delete the first row and shift the others */
- free(Rows[1]);
- memmove(&Rows[1], &Rows[2], sizeof(Row*) * (NumRows-2));
+ free(Rows[0]);
+ memmove(&Rows[0], &Rows[1], sizeof(Row*) * (NumRows-1));
Rows[NumRows-1] = calloc(1, sizeof(Row) + (NumCols * sizeof(UGlyph)));
Rows[NumRows-1]->off = (Rows[NumRows-2]->off + Rows[NumRows-2]->rlen);
/* fill in row content */
}
static void sync_view(Buf* buf, unsigned csr) {
- unsigned first = Rows[1]->off;
+ unsigned first = Rows[0]->off;
unsigned last = Rows[NumRows-1]->off + Rows[NumRows-1]->rlen - 1;
if (csr < first) {
scroll_up(buf, csr, first);
if (buf->insert_mode)
screen_reflow(buf);
/* find the cursor on the new screen */
- for (unsigned y = 1; y < NumRows; y++) {
+ for (unsigned y = 0; y < NumRows; y++) {
unsigned start = Rows[y]->off;
unsigned end = Rows[y]->off + Rows[y]->rlen - 1;
if (start <= csr && csr <= end) {
}
}
}
-
-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 = (Rune)buffer[i];
-}
#include "edit.h"
+#define BKGCLR (clr(CLR_BASE03))
+#define GTRCLR (clr(CLR_BASE02))
+#define CSRCLR (clr(CLR_BASE3))
+#define TXTCLR (clr(CLR_BASE0))
+
Buf Buffer;
unsigned CursorPos = 0;
unsigned TargetCol = 0;
+unsigned DotBeg = 0;
+unsigned DotEnd = 0;
enum ColorScheme ColorBase = DEFAULT_COLORSCHEME;
+XftColor Palette[CLR_COUNT][2];
struct {
Display* display;
Visual* visual;
/*****************************************************************************/
-static XftColor xftcolor(enum ColorId cid) {
- Color c = Palette[cid][ColorBase];
- XftColor xc;
- xc.color.red = 0xFF | ((c & 0x00FF0000) >> 8);
- xc.color.green = 0xFF | ((c & 0x0000FF00));
- xc.color.blue = 0xFF | ((c & 0x000000FF) << 8);
- xc.color.alpha = UINT16_MAX;
- XftColorAllocValue(X.display, X.visual, X.colormap, &xc.color, &xc);
- return xc;
+static void xftcolor(XftColor* xc, Color c) {
+ xc->color.red = 0xFF | ((c & 0x00FF0000) >> 8);
+ xc->color.green = 0xFF | ((c & 0x0000FF00));
+ xc->color.blue = 0xFF | ((c & 0x000000FF) << 8);
+ xc->color.alpha = UINT16_MAX;
+ XftColorAllocValue(X.display, X.visual, X.colormap, &(xc->color), xc);
+}
+
+XftColor* clr(int id) {
+ return &(Palette[id][ColorBase]);
}
static void deinit(void) {
X.pixmap = XCreatePixmap(X.display, X.window, Width, Height, X.depth);
X.xft = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap);
+ /* initialize the color pallette */
+ for (int i = 0; i < CLR_COUNT; i++) {
+ xftcolor(&Palette[i][LIGHT], ColorScheme[i][LIGHT]);
+ xftcolor(&Palette[i][DARK], ColorScheme[i][DARK]);
+ }
+
return XConnectionNumber(X.display);
}
X.xft = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap);
screen_setsize(
&Buffer,
- X.height / Fonts.base.height,
+ X.height / Fonts.base.height - 1,
X.width / Fonts.base.width);
}
break;
XftDrawGlyphFontSpec(X.xft, fg, specs, nspecs);
}
-static void redraw(void) {
- /* Allocate the colors */
- XftColor bkgclr = xftcolor(CLR_BASE03);
- XftColor gtrclr = xftcolor(CLR_BASE02);
- XftColor csrclr = xftcolor(CLR_BASE3);
- XftColor txtclr = xftcolor(CLR_BASE0);
+static void draw_status(XftColor* fg, unsigned ncols) {
+ UGlyph glyphs[ncols];
+ UGlyph* status = glyphs;
+ (status++)->rune = (Buffer.charset == BINARY ? 'B' : 'U');
+ (status++)->rune = (Buffer.crlf ? 'C' : 'N');
+ (status++)->rune = (Buffer.modified ? '*' : ' ');
+ (status++)->rune = ' ';
+ char* path = Buffer.path;
+ while(*path)
+ (status++)->rune = *path++;
+ draw_runes(0, 0, fg, NULL, glyphs, status - glyphs);
+}
+static void redraw(void) {
/* draw the background colors */
- XftDrawRect(X.xft, &bkgclr, 0, 0, X.width, X.height);
- XftDrawRect(X.xft, >rclr, 79 * Fonts.base.width, 0, Fonts.base.width, X.height);
- XftDrawRect(X.xft, &txtclr, 0, 0, X.width, Fonts.base.height);
+ XftDrawRect(X.xft, BKGCLR, 0, 0, X.width, X.height);
+ XftDrawRect(X.xft, GTRCLR, 79 * Fonts.base.width, 0, Fonts.base.width, X.height);
+ XftDrawRect(X.xft, TXTCLR, 0, 0, X.width, Fonts.base.height);
/* update the screen buffer and retrieve cursor coordinates */
unsigned csrx, csry;
/* flush the screen buffer */
unsigned nrows, ncols;
screen_getsize(&nrows, &ncols);
- screen_status(" %s %c %s",
- (Buffer.charset == BINARY ? "BIN" : "UTF-8"),
- (Buffer.modified ? '*' : ' '),
- Buffer.path
- );
+ draw_status(BKGCLR, ncols);
for (unsigned y = 0; y < nrows; y++) {
Row* row = screen_getrow(y);
- draw_runes(0, y, (y == 0 ? &bkgclr : &txtclr), NULL, row->cols, row->len);
+ draw_runes(0, y+1, TXTCLR, NULL, row->cols, row->len);
}
/* Place cursor on screen */
unsigned rwidth;
UGlyph* csrrune = screen_getglyph(csry, csrx, &rwidth);
if (Buffer.insert_mode) {
- XftDrawRect(X.xft, &csrclr, csrx * Fonts.base.width, csry * Fonts.base.height, 2, Fonts.base.height);
+ XftDrawRect(X.xft, CSRCLR, csrx * Fonts.base.width, (csry+1) * Fonts.base.height, 1, Fonts.base.height);
} else {
- XftDrawRect(X.xft, &csrclr, csrx * Fonts.base.width, csry * Fonts.base.height, rwidth * Fonts.base.width, Fonts.base.height);
- draw_runes(csrx, csry, &bkgclr, NULL, csrrune, 1);
+ XftDrawRect(X.xft, CSRCLR, csrx * Fonts.base.width, (csry+1) * Fonts.base.height, rwidth * Fonts.base.width, Fonts.base.height);
+ draw_runes(csrx, csry+1, BKGCLR, NULL, csrrune, 1);
}
/* flush pixels to the screen */