commit a0b77c70ccde005199b2bc7aff8e62b21b3919e6
parent 8bbe4f33f1e9a0a92627b7acc613d453fde64f87
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 3 Jul 2020 19:59:34 +0200
save and restore cursor
This improves the screen scrolling. Tested on xterm.
Diffstat:
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -359,6 +359,20 @@ cursormode(int on)
}
void
+cursorsave(void)
+{
+ /*fputs("\x1b""7", stdout);*/
+ putp(tparm(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+void
+cursorrestore(void)
+{
+ /*fputs("\x1b""8", stdout);*/
+ putp(tparm(restore_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+void
cursormove(int x, int y)
{
/*printf("\x1b[%d;%dH", y + 1, x + 1);*/
@@ -582,6 +596,7 @@ pane_row_draw(struct pane *p, off_t pos)
row = pane_row_get(p, pos);
y = p->y + (pos % p->height); /* relative position on screen */
+ cursorsave();
cursormove(p->x, y);
r = 0;
@@ -600,6 +615,7 @@ pane_row_draw(struct pane *p, off_t pos)
printf("%-*.*s", p->width, p->width, "");
if (r)
attrmode(ATTR_RESET);
+ cursorrestore();
}
void
@@ -817,6 +833,7 @@ scrollbar_draw(struct scrollbar *s)
if (s->hidden || !s->dirty)
return;
+ cursorsave();
if (!s->focused)
attrmode(ATTR_FAINT_ON);
for (y = 0; y < s->size; y++) {
@@ -831,6 +848,7 @@ scrollbar_draw(struct scrollbar *s)
}
if (!s->focused)
attrmode(ATTR_RESET);
+ cursorrestore();
s->dirty = 0;
}
@@ -886,6 +904,7 @@ uiprompt(int x, int y, char *fmt, ...)
buf[sizeof(buf) - 1] = '\0';
va_end(ap);
+ cursorsave();
cursormove(x, y);
attrmode(ATTR_REVERSE_ON);
fputs(buf, stdout);
@@ -898,6 +917,7 @@ uiprompt(int x, int y, char *fmt, ...)
input = lineeditor();
cursormode(0);
+ cursorrestore();
return input;
}
@@ -907,10 +927,13 @@ statusbar_draw(struct statusbar *s)
{
if (s->hidden || !s->dirty)
return;
+
+ cursorsave();
cursormove(s->x, s->y);
attrmode(ATTR_REVERSE_ON);
printpad(s->text, s->width);
attrmode(ATTR_REVERSE_OFF);
+ cursorrestore();
s->dirty = 0;
}