aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-29 22:27:38 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-29 22:27:38 -0700
commitc4667ee965f35759454355a3440996d0b804c101 (patch)
tree9a70f723c254e260480c72e2eaea3a78597efbdd
parent95c47d4172d5c14d87fad72a28e566544e72b591 (diff)
downloadpw-c4667ee965f35759454355a3440996d0b804c101.tar.gz
pw-c4667ee965f35759454355a3440996d0b804c101.tar.bz2
pw-c4667ee965f35759454355a3440996d0b804c101.zip
Eliminate wasteful redraws of snapshot.
When we do need to redraw the snapshot even though the data isn't dirty, or we are frozen, or waiting for a trigger, there is a new stat_force flag to request it.
-rw-r--r--pw.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/pw.c b/pw.c
index be72687..b9868c6 100644
--- a/pw.c
+++ b/pw.c
@@ -37,7 +37,8 @@ enum status_flags {
stat_htmode = 8, // head trigger mode
stat_ttmode = 16, // tail trigger mode
stat_trgrd = 32, // triggered flag
- stat_grep = 64 // grep mode
+ stat_grep = 64, // grep mode
+ stat_force = 128 // force refresh even if clean
};
typedef struct grep {
@@ -308,8 +309,8 @@ static void drawstatus(int columns, unsigned stat, char *cmd)
fflush(stdout);
}
-static void redraw(char **circbuf, int nlines, int hpos,
- int columns, unsigned stat, char *cmd)
+static unsigned redraw(char **circbuf, int nlines, int hpos,
+ int columns, unsigned stat, char *cmd)
{
if ((stat & stat_susp) == 0 &&
(stat & (stat_htmode | stat_trgrd)) != stat_htmode &&
@@ -325,12 +326,17 @@ static void redraw(char **circbuf, int nlines, int hpos,
drawline(circbuf[i], hpos, columns);
snapshot[i] = dsref(circbuf[i]);
}
- } else {
+ stat &= ~(stat_dirty | stat_trgrd);
+ } else if ((stat & stat_force)) {
printf("\r\033[%dA", snaplines);
for (int i = 0; i < snaplines; i++)
drawline(snapshot[i], hpos, columns);
+ stat &= ~stat_force;
+ } else {
+ clrline();
}
drawstatus(columns, stat, cmd);
+ return stat;
}
static int getzp(const char *str, char **err)
@@ -670,8 +676,7 @@ int main(int argc, char **argv)
if (feof(stdin) || (errno != EAGAIN && errno != EWOULDBLOCK)) {
nfds = 1;
stat |= stat_eof;
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~stat_dirty;
+ stat = redraw(circbuf, nlines, hpos, columns, stat, curcmd);
if (!ferror(stdin))
exit_status = 0;
if (auto_quit) {
@@ -745,6 +750,7 @@ int main(int argc, char **argv)
columns = ws.ws_col;
}
+ stat |= stat_force;
force = 1;
}
@@ -772,21 +778,16 @@ int main(int argc, char **argv)
if ((stat & stat_dirty) && nlines == maxlines)
force = 1;
lasttime = now;
- stat &= ~stat_dirty;
}
}
- if (force) {
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~(stat_dirty | stat_trgrd);
- }
+ if (force)
+ stat = redraw(circbuf, nlines, hpos, columns, stat, curcmd);
if (poll(pe, nfds, pollms) <= 0) {
if (pollms) {
- if ((stat & stat_dirty) && nlines == maxlines) {
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~stat_dirty;
- }
+ if ((stat & stat_dirty) && nlines == maxlines)
+ stat = redraw(circbuf, nlines, hpos, columns, stat, curcmd);
if (kbd_state == kbd_esc || kbd_state == kbd_result) {
kbd_state = kbd_cmd;
curcmd = 0;
@@ -808,8 +809,7 @@ int main(int argc, char **argv)
ttyset(ttyfd, &tty_new);
for (int i = 0; i < nlines; i++)
puts("");
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~stat_dirty;
+ stat = redraw(circbuf, nlines, hpos, columns, stat | stat_force, curcmd);
continue;
}
@@ -828,26 +828,25 @@ int main(int argc, char **argv)
case 'h':
if (hpos >= 8) {
hpos -= 8;
- stat |= stat_dirty;
+ stat |= stat_force;
}
break;
case 'l':
if (hpos < 10000) {
hpos += 8;
- stat |= stat_dirty;
+ stat |= stat_force;
}
break;
case '0':
hpos = 0;
- stat |= stat_dirty;
+ stat |= stat_force;
break;
case ' ':
if ((stat & stat_eof) == 0)
- stat |= (stat_dirty | stat_susp);
+ stat |= stat_susp;
break;
case CR:
stat &= ~stat_susp;
- stat |= stat_dirty;
break;
case ESC:
kbd_prev = kbd_state;
@@ -1044,8 +1043,7 @@ int main(int argc, char **argv)
}
if ((stat & stat_dirty)) {
- redraw(circbuf, nlines, hpos, columns, stat, curcmd);
- stat &= ~stat_dirty;
+ stat = redraw(circbuf, nlines, hpos, columns, stat, curcmd);
} else switch (kbd_state) {
case kbd_colon: case kbd_trig: case kbd_result: case kbd_cmd:
clrline();