Skip to content

Commit 110ccc5

Browse files
committed
vile: sort out the rendering logic
Some of this needs transplanting into fleamacs next. The renderer still doesn't know how to render a line wider than the display by scrolling it across. This needs fixing to be useful on many machines.
1 parent ae5874e commit 110ccc5

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

Applications/util/vile.c

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void con_flush(void)
105105
static const char hex[] = "0123456789ABCDEF";
106106

107107
/* Put a character to the screen. We handle unprintables and tabs */
108-
void con_putc(uint8_t c)
108+
void con_putc(uint_fast8_t c)
109109
{
110110
if (screeny >= screen_height)
111111
return;
@@ -115,7 +115,7 @@ void con_putc(uint8_t c)
115115
con_putc(' ');
116116
return;
117117
}
118-
if (c > 127) {
118+
if (c >= 127) {
119119
con_puts("\\x");
120120
con_putc(hex[c >> 4]);
121121
con_putc(hex[c & 0x0F]);
@@ -150,8 +150,8 @@ static void con_twrite(char *p, int n)
150150
/* Write a string of symbols including quoting */
151151
void con_puts(const char *s)
152152
{
153-
uint8_t c;
154-
while ((c = (uint8_t) * s++) != 0)
153+
uint_fast8_t c;
154+
while ((c = (uint_fast8_t) * s++) != 0)
155155
con_putc(c);
156156
}
157157

@@ -214,7 +214,7 @@ void con_clear_to_eol(void)
214214
void con_clear_to_bottom(void)
215215
{
216216
/* Most terminals have a clear to end of screen */
217-
if (t_clreos && 0)
217+
if (t_clreos)
218218
con_twrite(t_clreos, screen_height);
219219
/* If not then clear each line, which may in turn emit
220220
a lot of spaces in desperation */
@@ -230,7 +230,7 @@ void con_clear_to_bottom(void)
230230

231231
void con_clear(void)
232232
{
233-
con_goto(0, 0);
233+
con_force_goto(0, 0);
234234
con_clear_to_bottom();
235235
}
236236

@@ -632,7 +632,7 @@ keytable_t table[] = {
632632
{'w', 0, wright},
633633
{'^', NORPT, lnbegin},
634634
{'$', NORPT, lnend},
635-
{'G', USERPT, do_goto}, /* Should be 0G */
635+
{'G', USERPT, do_goto}, /* Should be 1G */
636636
{'i', NORPT, insert_mode},
637637
{'I', NORPT, insert_before},
638638
{'J', 0, join},
@@ -694,7 +694,7 @@ int pos(char *pointer)
694694
int do_goto(void)
695695
{
696696
if (repeat == -1) {
697-
epage = indexp = pos(ebuf);
697+
epage = indexp = pos(buf);
698698
return 0;
699699
}
700700
/* FIXME: we need to do line tracking really to do this nicely */
@@ -906,12 +906,12 @@ int swapchars(void)
906906
/* The hard case - moving a newline */
907907
dirtyn = 1;
908908
if (x == '\n' || *q == '\n') {
909-
dirty[row] = 255;
910-
dirty[row + 1] = 255;
909+
dirty[row] = 0;
910+
dirty[row + 1] = 0;
911911
} else {
912912
/* FIXME: optimize this for the case where
913913
both have the same on screen length */
914-
dirty[row] = col;
914+
dirty[row] = col - 1;
915915
*p = *q;
916916
*q = x;
917917
}
@@ -1322,8 +1322,8 @@ int noop(void)
13221322

13231323
void status_wipe(void)
13241324
{
1325-
con_goto(screen_height - 1, 0);
1326-
con_clear_to_eol();
1325+
dirty[screen_height - 1] = 0;
1326+
display(0);
13271327
status_up = 0;
13281328
}
13291329

@@ -1458,7 +1458,7 @@ void warning(const char *p)
14581458

14591459
void dirty_below(void)
14601460
{
1461-
memset(dirty, 0, MAX_HEIGHT - (row + 1));
1461+
memset(dirty + row, 0, MAX_HEIGHT - (row + 1));
14621462
dirtyn = 1;
14631463
}
14641464

@@ -1489,30 +1489,30 @@ void display(int redraw)
14891489
{
14901490
char *p;
14911491
unsigned int i, j;
1492-
int opage = page;
1492+
int opage = 0;
14931493
uint_fast8_t inpos = 0;
14941494
uint8_t *dirtyp = dirty;
14951495

1496-
if (indexp < page)
1496+
if (indexp < page) {
1497+
/* We don't yet do backscrolls */
1498+
redraw = 1;
14971499
page = prevline(indexp);
1500+
}
1501+
/* Need to move down */
14981502
if (epage <= indexp) {
14991503
page = nextline(indexp);
15001504
i = page == pos(ebuf) ? screen_height - 2 : screen_height;
1501-
while (0 < i--)
1505+
while (0 < i--) {
1506+
opage++;
15021507
page = prevline(page - 1);
1508+
}
1509+
/* Try and scroll the screen */
1510+
if (con_scroll(opage))
1511+
adjust_dirty(opage);
1512+
else
1513+
redraw = 1;
15031514
}
15041515

1505-
/* opage is the delta so we know if we are going to scroll. If it's
1506-
negative then we need to reverse scroll, if its positive we need
1507-
to normal scroll */
1508-
opage -= page;
1509-
1510-
/* If we can't scroll this then redraw the lot */
1511-
if (opage && con_scroll(opage))
1512-
redraw = 1;
1513-
else
1514-
adjust_dirty(opage);
1515-
15161516
if (redraw) {
15171517
dirtyn = 1;
15181518
dirty_all();
@@ -1543,11 +1543,11 @@ void display(int redraw)
15431543
}
15441544
p = ptr(epage);
15451545
/* We ran out of screen or buffer */
1546-
if (screen_height <= i || ebuf <= p)
1546+
if (i >= screen_height || ebuf <= p)
15471547
break;
15481548
/* Normal characters */
15491549
if (*p != '\n') {
1550-
uint8_t s = con_size_x(*p, j);
1550+
uint_fast8_t s = con_size_x(*p, j);
15511551
/* If the symbol fits and is beyond our dirty marker */
15521552
if (j >= *dirtyp && j + s < screen_width) {
15531553
/* Move cursor only if needed. We assume
@@ -1577,17 +1577,19 @@ void display(int redraw)
15771577
++epage;
15781578
}
15791579
/* Clear the end of our final line */
1580-
if (*dirtyp != 255) {
1580+
if (j && *dirtyp != 255) {
15811581
if (!inpos)
15821582
con_goto(i, j);
15831583
con_clear_to_eol();
15841584
*dirtyp = 255;
1585+
dirtyp++;
1586+
i++;
15851587
}
15861588
/* Now mark out the unused lines with ~ markers if needed */
15871589
j = i + 1;
15881590
while (++i < tilde_start) {
1589-
if (*dirtyp) {
1590-
*dirtyp = 0;
1591+
if (*dirtyp != 255) {
1592+
*dirtyp = 255;
15911593
con_goto(i, 0);
15921594
con_putc('~');
15931595
con_clear_to_eol();
@@ -1640,10 +1642,15 @@ int main(int argc, char *argv[])
16401642
oom();
16411643
} else {
16421644
buf = malloc(65535);
1643-
if (buf == NULL)
1644-
oom();
16451645
ebuf = buf + 65535;
1646+
if (buf == NULL) {
1647+
buf = malloc(32768);
1648+
ebuf = buf + 32768;
1649+
if (buf == NULL)
1650+
oom();
1651+
}
16461652
}
1653+
16471654
gap = buf;
16481655
egap = ebuf;
16491656
if (argc < 2)

0 commit comments

Comments
 (0)