/* Screen management functions
*****************************************************************************/
typedef struct {
+ unsigned off;
+ unsigned rlen;
unsigned len;
Rune cols[];
} Row;
void screen_clear(void);
Row* screen_getrow(unsigned row);
void screen_clearrow(unsigned row);
-void screen_setcell(unsigned row, unsigned col, Rune r);
+void screen_setrowoff(unsigned row, unsigned off);
+unsigned screen_setcell(unsigned row, unsigned col, Rune r);
Rune screen_getcell(unsigned row, unsigned col);
/* Miscellaneous Functions
if (!scrrow) return;
for (unsigned i = 0; i < NumCols; i++)
scrrow->cols[i] = (Rune)' ';
- scrrow->len = 0;
+ scrrow->rlen = 0;
+ scrrow->len = 0;
}
-void screen_setcell(unsigned row, unsigned col, Rune r)
+void screen_setrowoff(unsigned row, unsigned off)
{
- if (row >= NumRows || col >= NumCols) return;
+ screen_getrow(row)->off = off;
+}
+
+unsigned screen_setcell(unsigned row, unsigned col, Rune r)
+{
+ if (row >= NumRows || col >= NumCols) return 0;
Row* scrrow = screen_getrow(row);
- scrrow->cols[col] = r;
- if (col+1 >= scrrow->len)
- scrrow->len = col+1;
+ /* write the rune to the screen buf */
+ unsigned ncols = 1;
+ if (r == '\t') {
+ scrrow->cols[col] = ' ';
+ ncols = (TabWidth - (col % TabWidth));
+ } else if (r != '\n') {
+ scrrow->cols[col] = r;
+ }
+ /* Update lengths */
+ scrrow->rlen += 1;
+ if ((col + ncols) > scrrow->len)
+ scrrow->len = col + ncols;
+ return ncols;
}
Rune screen_getcell(unsigned row, unsigned col)
screen_clearrow(0);
for (unsigned y = 1; y < nrows; y++) {
screen_clearrow(y);
- for (unsigned x = 0; x < ncols; x++) {
+ screen_setrowoff(y, pos);
+ for (unsigned x = 0; x < ncols;) {
if (CursorPos == pos)
csrx = x, csry = y;
Rune r = buf_get(&Buffer, pos++);
- if (r == '\n') {
- screen_setcell(y,x,' ');
- break;
- } else if (r == '\t') {
- screen_setcell(y,x,' ');
- x += TabWidth - (x % TabWidth) - 1;
- } else {
- screen_setcell(y,x,r);
- }
+ unsigned cols = screen_setcell(y,x,r);
+ x += cols;
+ if (r == '\n') break;
}
}
EndPos = pos-1;
/* flush the screen buffer */
for (unsigned y = 0; y < nrows; y++) {
Row* row = screen_getrow(y);
- if (row->len > 0)
- XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
+ XftDrawString32(X.xft, &txtclr, X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len));
}
/* Place cursor on screen */
if (InsertMode) {
XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, 2, fheight);
} else {
- unsigned width = 1;
- if ('\t' == buf_get(&Buffer, CursorPos))
- width = TabWidth - (csrx % TabWidth);
+ unsigned width = ('\t' == buf_get(&Buffer, CursorPos) ? (TabWidth - (csrx % TabWidth)) : 1);
XftDrawRect(X.xft, &csrclr, csrx * fwidth, csry * fheight + X.font->descent, width * fwidth, fheight);
XftDrawString32(X.xft, &bkgclr, X.font, csrx * fwidth, (csry+1) * fheight, (FcChar32*)&csrrune, 1);
}