diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-04-27 01:11:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-04-27 01:11:32 -0700 |
commit | d56dce29ed972af462e6c497407adc383039482e (patch) | |
tree | 856118bd143275a2993775b92c31c0622875c8fd | |
parent | f133a1da76f32c6b54a71e2170b7d1ab66910ac4 (diff) | |
download | pw-d56dce29ed972af462e6c497407adc383039482e.tar.gz pw-d56dce29ed972af462e6c497407adc383039482e.tar.bz2 pw-d56dce29ed972af462e6c497407adc383039482e.zip |
Rethink suspend mode: FIFO always freewheels.
-rw-r--r-- | pw.1 | 37 | ||||
-rw-r--r-- | pw.c | 49 |
2 files changed, 38 insertions, 48 deletions
@@ -143,18 +143,18 @@ Scroll the display to the right. Reset scroll to first column. .IP \fISpace\fP -Suspend the entry of lines of new lines of input into the display FIFO. -In suspended mode, input continues to be read from the pipe, but is discarded. -The status string +Suspend the refresh of the display. In suspended mode, input continues to pass +through the FIFO, but all display refresh is stopped. The status indicator .B SUSPENDED -is displayed below the data. +is displayed below the data. If the the status is already +.B EOF +then suspend mode cannot be entered. .IP \fIEnter\fP -Cancel suspended mode, and resume adding data to the FIFO. The +Cancel suspended mode, resuming display refresh. The display is refreshed +immediately and the .B SUSPENDED -status string disappears. If the status is already -.B EOF -then suspend mode cannot be entered. +status indicator disappears. .IP \fB:\fP Enter colon command mode. In colon command mode, the status line clears @@ -176,22 +176,22 @@ are documented in the COLON COMMANDS section below. .SH COLON COMMANDS -First, some general remarks. the current contents of the FIFO buffer may have -changed relative to what is displayed on the screen. The space between the -command and the argument may be omitted. The command is replaced with -a result string, which persists over the poll interval period. The longer -the poll interval +First, some general remarks. Display refresh doesn't pause during the editing +of a colon command. If that is required, the suspend command must be used. +The space between the command and the argument may be omitted. After a command +is executed, a result message appears in its place. This message persists over +the poll interval period. The longer the poll interval .RB ( -i " option), the longer the result message persists. .IP "\fB:w\fP \fIfilename\fP" -Write the current contents of the FIFO buffer into the specified file. +Write the current contents of the display into the specified file. .IP "\fB:a\fP \fIfilename\fP" -Append the current contents of the FIFO buffer into the specified file. +Append the current contents of the display into the specified file. .IP "\fB:!\fP \fIfilename\fP" -Pipe the current contents of the FIFO buffers into the specified command. +Pipe the current contents of of the display into the specified command. .PP Any other command results in a brief error message. @@ -274,9 +274,6 @@ terminal abstraction library/data. The intervals and number of lines cannot be dynamically adjusted. -Suspend mode is confusing; it doesn't necessarily freeze what is on the -screen. - There is no support for unwrapping long lines, which would be useful for copy and paste. @@ -286,6 +283,8 @@ During the .B :! command's execution, the TTY settings are not restored. +Most of these issues are easy; patches welcome. + .SH AUTHOR Kaz Kylheku <kaz@kylheku.com> @@ -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; |