aboutsummaryrefslogtreecommitdiffstats
path: root/pw.c
diff options
context:
space:
mode:
Diffstat (limited to 'pw.c')
-rw-r--r--pw.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/pw.c b/pw.c
index d0990d2..ecc37c5 100644
--- a/pw.c
+++ b/pw.c
@@ -192,15 +192,19 @@ static void drawstatus(unsigned stat, char *cmd)
static void redraw(char **circbuf, int nlines, int hpos,
int columns, unsigned stat, char *cmd)
{
- if (snapshot) {
- for (int i = 0; i < snaplines; i++)
- dsdrop(snapshot[i]);
- }
- snaplines = nlines;
- printf("\r\033[%dA\033[J", nlines);
- for (int i = 0; i < nlines; i++) {
- drawline(circbuf[i], hpos, columns);
- snapshot[i] = dsref(circbuf[i]);
+ if ((stat & stat_susp) == 0) {
+ if (snapshot) {
+ for (int i = 0; i < snaplines; i++)
+ dsdrop(snapshot[i]);
+ }
+ snaplines = nlines;
+ printf("\r\033[%dA\033[J", nlines);
+ for (int i = 0; i < nlines; i++) {
+ drawline(circbuf[i], hpos, columns);
+ snapshot[i] = dsref(circbuf[i]);
+ }
+ } else {
+ clear_cur_line();
}
drawstatus(stat, cmd);
}
@@ -391,19 +395,13 @@ int main(int argc, char **argv)
if ((stat & stat_eof) == 0 && pe[1].revents) {
if ((line = getln(stdin))) {
if (nlines == maxlines) {
- if ((stat & stat_susp)) {
- dsdrop(line);
- } else {
- dsdrop(circbuf[0]);
- memmove(circbuf, circbuf + 1, (nlines - 1) * sizeof *circbuf);
- circbuf[nlines - 1] = line;
- stat |= stat_dirty;
- }
+ dsdrop(circbuf[0]);
+ memmove(circbuf, circbuf + 1, (nlines - 1) * sizeof *circbuf);
+ circbuf[nlines - 1] = line;
+ stat |= stat_dirty;
} else {
- if ((stat & stat_susp)) {
- dsdrop(line);
- } else {
- circbuf[nlines++] = line;
+ circbuf[nlines++] = line;
+ if ((stat & stat_susp) == 0) {
snapshot[snaplines++] = dsref(line);
clear_cur_line();
drawline(line, hpos, columns);
@@ -455,15 +453,8 @@ int main(int argc, char **argv)
stat |= stat_dirty;
break;
case ' ':
- if ((stat & stat_eof) == 0) {
+ if ((stat & stat_eof) == 0)
stat |= (stat_dirty | stat_susp);
- for (int i = 0; i < nlines || i < snaplines; i++) {
- if (i < nlines)
- dsdrop(circbuf[i]);
- circbuf[i] = (i < snaplines) ? dsref(snapshot[i]) : 0;
- }
- nlines = snaplines;
- }
break;
case 13:
stat &= ~stat_susp;