aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-29 03:11:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-29 03:11:35 -0700
commit68429e4f41e0691acb37e73f35e42a5d12f5302c (patch)
tree9bf27474911f208e95c0c23528c5164278507bce /pw.c
parent324c9bacb37b1c967e9d03a983147f5ded603ad3 (diff)
downloadpw-68429e4f41e0691acb37e73f35e42a5d12f5302c.tar.gz
pw-68429e4f41e0691acb37e73f35e42a5d12f5302c.tar.bz2
pw-68429e4f41e0691acb37e73f35e42a5d12f5302c.zip
Use clear-to-end-of-line for flicker-free updates.
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/pw.c b/pw.c
index dd0160e..e533a5e 100644
--- a/pw.c
+++ b/pw.c
@@ -227,6 +227,18 @@ static void usage(const char *name)
exit(EXIT_FAILURE);
}
+static void clrline()
+{
+ printf("\r\033[J");
+}
+
+static void clreol(int nl)
+{
+ printf("\033[K");
+ if (nl)
+ putchar('\n');
+}
+
static void drawline(const char *line, int hpos, int columns)
{
size_t len = dslen(line);
@@ -238,22 +250,19 @@ static void drawline(const char *line, int hpos, int columns)
putchar('>');
}
if (len < (size_t) columns - 1) {
- puts(line);
+ fputs(line, stdout);
+ clreol(1);
} else {
for (int i = 0; i < columns - 2; i++)
putchar(line[i]);
puts("<");
}
} else {
- puts(">");
+ putchar('>');
+ clreol(1);
}
}
-static void clrline()
-{
- printf("\r\033[J");
-}
-
static void drawstatus(int columns, unsigned stat, char *cmd)
{
char status[cmdsize] = "", *ptr = status;
@@ -292,6 +301,7 @@ static void drawstatus(int columns, unsigned stat, char *cmd)
}
fputs(status, stdout);
+ clreol(0);
fflush(stdout);
}
@@ -307,13 +317,13 @@ static void redraw(char **circbuf, int nlines, int hpos,
dsdrop(snapshot[i]);
}
snaplines = nlines;
- printf("\r\033[%dA\033[J", nlines);
+ printf("\r\033[%dA", nlines);
for (int i = 0; i < nlines; i++) {
drawline(circbuf[i], hpos, columns);
snapshot[i] = dsref(circbuf[i]);
}
} else {
- printf("\r\033[%dA\033[J", snaplines);
+ printf("\r\033[%dA", snaplines);
for (int i = 0; i < snaplines; i++)
drawline(snapshot[i], hpos, columns);
}