@@ -105,7 +105,7 @@ void con_flush(void)
105
105
static const char hex [] = "0123456789ABCDEF" ;
106
106
107
107
/* 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 )
109
109
{
110
110
if (screeny >= screen_height )
111
111
return ;
@@ -115,7 +115,7 @@ void con_putc(uint8_t c)
115
115
con_putc (' ' );
116
116
return ;
117
117
}
118
- if (c > 127 ) {
118
+ if (c >= 127 ) {
119
119
con_puts ("\\x" );
120
120
con_putc (hex [c >> 4 ]);
121
121
con_putc (hex [c & 0x0F ]);
@@ -150,8 +150,8 @@ static void con_twrite(char *p, int n)
150
150
/* Write a string of symbols including quoting */
151
151
void con_puts (const char * s )
152
152
{
153
- uint8_t c ;
154
- while ((c = (uint8_t ) * s ++ ) != 0 )
153
+ uint_fast8_t c ;
154
+ while ((c = (uint_fast8_t ) * s ++ ) != 0 )
155
155
con_putc (c );
156
156
}
157
157
@@ -214,7 +214,7 @@ void con_clear_to_eol(void)
214
214
void con_clear_to_bottom (void )
215
215
{
216
216
/* Most terminals have a clear to end of screen */
217
- if (t_clreos && 0 )
217
+ if (t_clreos )
218
218
con_twrite (t_clreos , screen_height );
219
219
/* If not then clear each line, which may in turn emit
220
220
a lot of spaces in desperation */
@@ -230,7 +230,7 @@ void con_clear_to_bottom(void)
230
230
231
231
void con_clear (void )
232
232
{
233
- con_goto (0 , 0 );
233
+ con_force_goto (0 , 0 );
234
234
con_clear_to_bottom ();
235
235
}
236
236
@@ -632,7 +632,7 @@ keytable_t table[] = {
632
632
{'w' , 0 , wright },
633
633
{'^' , NORPT , lnbegin },
634
634
{'$' , NORPT , lnend },
635
- {'G' , USERPT , do_goto }, /* Should be 0G */
635
+ {'G' , USERPT , do_goto }, /* Should be 1G */
636
636
{'i' , NORPT , insert_mode },
637
637
{'I' , NORPT , insert_before },
638
638
{'J' , 0 , join },
@@ -694,7 +694,7 @@ int pos(char *pointer)
694
694
int do_goto (void )
695
695
{
696
696
if (repeat == -1 ) {
697
- epage = indexp = pos (ebuf );
697
+ epage = indexp = pos (buf );
698
698
return 0 ;
699
699
}
700
700
/* FIXME: we need to do line tracking really to do this nicely */
@@ -906,12 +906,12 @@ int swapchars(void)
906
906
/* The hard case - moving a newline */
907
907
dirtyn = 1 ;
908
908
if (x == '\n' || * q == '\n' ) {
909
- dirty [row ] = 255 ;
910
- dirty [row + 1 ] = 255 ;
909
+ dirty [row ] = 0 ;
910
+ dirty [row + 1 ] = 0 ;
911
911
} else {
912
912
/* FIXME: optimize this for the case where
913
913
both have the same on screen length */
914
- dirty [row ] = col ;
914
+ dirty [row ] = col - 1 ;
915
915
* p = * q ;
916
916
* q = x ;
917
917
}
@@ -1322,8 +1322,8 @@ int noop(void)
1322
1322
1323
1323
void status_wipe (void )
1324
1324
{
1325
- con_goto ( screen_height - 1 , 0 ) ;
1326
- con_clear_to_eol ( );
1325
+ dirty [ screen_height - 1 ] = 0 ;
1326
+ display ( 0 );
1327
1327
status_up = 0 ;
1328
1328
}
1329
1329
@@ -1458,7 +1458,7 @@ void warning(const char *p)
1458
1458
1459
1459
void dirty_below (void )
1460
1460
{
1461
- memset (dirty , 0 , MAX_HEIGHT - (row + 1 ));
1461
+ memset (dirty + row , 0 , MAX_HEIGHT - (row + 1 ));
1462
1462
dirtyn = 1 ;
1463
1463
}
1464
1464
@@ -1489,30 +1489,30 @@ void display(int redraw)
1489
1489
{
1490
1490
char * p ;
1491
1491
unsigned int i , j ;
1492
- int opage = page ;
1492
+ int opage = 0 ;
1493
1493
uint_fast8_t inpos = 0 ;
1494
1494
uint8_t * dirtyp = dirty ;
1495
1495
1496
- if (indexp < page )
1496
+ if (indexp < page ) {
1497
+ /* We don't yet do backscrolls */
1498
+ redraw = 1 ;
1497
1499
page = prevline (indexp );
1500
+ }
1501
+ /* Need to move down */
1498
1502
if (epage <= indexp ) {
1499
1503
page = nextline (indexp );
1500
1504
i = page == pos (ebuf ) ? screen_height - 2 : screen_height ;
1501
- while (0 < i -- )
1505
+ while (0 < i -- ) {
1506
+ opage ++ ;
1502
1507
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 ;
1503
1514
}
1504
1515
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
-
1516
1516
if (redraw ) {
1517
1517
dirtyn = 1 ;
1518
1518
dirty_all ();
@@ -1543,11 +1543,11 @@ void display(int redraw)
1543
1543
}
1544
1544
p = ptr (epage );
1545
1545
/* We ran out of screen or buffer */
1546
- if (screen_height <= i || ebuf <= p )
1546
+ if (i >= screen_height || ebuf <= p )
1547
1547
break ;
1548
1548
/* Normal characters */
1549
1549
if (* p != '\n' ) {
1550
- uint8_t s = con_size_x (* p , j );
1550
+ uint_fast8_t s = con_size_x (* p , j );
1551
1551
/* If the symbol fits and is beyond our dirty marker */
1552
1552
if (j >= * dirtyp && j + s < screen_width ) {
1553
1553
/* Move cursor only if needed. We assume
@@ -1577,17 +1577,19 @@ void display(int redraw)
1577
1577
++ epage ;
1578
1578
}
1579
1579
/* Clear the end of our final line */
1580
- if (* dirtyp != 255 ) {
1580
+ if (j && * dirtyp != 255 ) {
1581
1581
if (!inpos )
1582
1582
con_goto (i , j );
1583
1583
con_clear_to_eol ();
1584
1584
* dirtyp = 255 ;
1585
+ dirtyp ++ ;
1586
+ i ++ ;
1585
1587
}
1586
1588
/* Now mark out the unused lines with ~ markers if needed */
1587
1589
j = i + 1 ;
1588
1590
while (++ i < tilde_start ) {
1589
- if (* dirtyp ) {
1590
- * dirtyp = 0 ;
1591
+ if (* dirtyp != 255 ) {
1592
+ * dirtyp = 255 ;
1591
1593
con_goto (i , 0 );
1592
1594
con_putc ('~' );
1593
1595
con_clear_to_eol ();
@@ -1640,10 +1642,15 @@ int main(int argc, char *argv[])
1640
1642
oom ();
1641
1643
} else {
1642
1644
buf = malloc (65535 );
1643
- if (buf == NULL )
1644
- oom ();
1645
1645
ebuf = buf + 65535 ;
1646
+ if (buf == NULL ) {
1647
+ buf = malloc (32768 );
1648
+ ebuf = buf + 32768 ;
1649
+ if (buf == NULL )
1650
+ oom ();
1651
+ }
1646
1652
}
1653
+
1647
1654
gap = buf ;
1648
1655
egap = ebuf ;
1649
1656
if (argc < 2 )
0 commit comments