diff options
-rw-r--r-- | pw.1 | 33 | ||||
-rw-r--r-- | pw.c | 60 |
2 files changed, 89 insertions, 4 deletions
@@ -238,6 +238,16 @@ and characters which indicate line truncation and pane separation are shown in inverse video (dark foreground, light background). +.IP \fBCtrl-G\fP +Shows the status of the display parameters, in a form which can be +given to the +.B -p +option as an argument in order to re-create the same configuration. +The parameters are four non-negative integers, all in character units. +The documentation for the +.B -p +option explains the numbers. + .IP \fISpace\fP Suspend the acquisition of new snapshots. In suspended mode, input continues to pass through the FIFO, but new snapshots of data aren't @@ -744,6 +754,29 @@ option. If neither option is used, then .I pattern is interpreted as a BRE. +.IP "\fB-p\fP [\fIinteger\fP[,\fIinteger\fP[,\fIinteger\fP[,\fIinteger\fP]]]] +Specify the display parameters, as comma-separated non-negative integers. +The meaning of these integer values is: +.RS +.IP 1. +horizontal scroll position; +.IP 2. +width of left pane; +.IP 3. +width of middle pane; and +.IP 4. +middle pane view offset. +.PP +All four numbers are optional, and default to zero if omitted. Since +.B -p +requires an argument, the only way all four may be omitted is if a blank +or empty argument is given. +The +.B Ctrl-G +command displays these same parameters in the same format, so it is possible to +set them up interactively and then copy the values shown by +.BR Ctrl-G . + .SH ENVIRONMENT .I pw @@ -578,7 +578,7 @@ static void redraw(pwstate *pw) drawstatus(pw); } -static int getzp(const char *str, char **err) +static int getznn(const char *str, char **err) { char *endp; long val = strtol(str, &endp, 10); @@ -587,9 +587,8 @@ static int getzp(const char *str, char **err) *err = dsdup("number expected"); return -1; } - if (val <= 0) { - *err = dsdup("positive value required"); + *err = dsdup("non-negative value required"); return -1; } @@ -601,6 +600,18 @@ static int getzp(const char *str, char **err) return val; } +static int getzp(const char *str, char **err) +{ + int val = getznn(str, err); + + if (val <= 0) { + *err = dsdup("positive value required"); + return -1; + } + + return val; +} + static int getms(const char *str, char **err) { errno = 0; @@ -850,7 +861,7 @@ int main(int argc, char **argv) } } - while ((opt = getopt(argc, argv, "n:i:l:dEBg:q:m:")) != -1) { + while ((opt = getopt(argc, argv, "n:i:l:dEBg:q:m:p:")) != -1) { switch (opt) { case 'n': { @@ -938,6 +949,39 @@ int main(int argc, char **argv) maxlen = max(72, val); } break; + case 'p': + { + char *err; + char *hpos = strtok(optarg, ", \t"); + char *lpane = hpos ? strtok(0, ", \t") : 0; + char *rpane = lpane ? strtok(0, ", \t") : 0; + char *vs2pos = rpane ? strtok(0, ", \t") : 0; + + if (hpos) { + if ((pw.hpos = getznn(hpos, &err)) < 0) + error("-%c option: bad horizontal scroll offset %s: %s\n", + opt, hpos, err); + } + + if (lpane) { + if ((pw.vsplit1 = getznn(lpane, &err)) < 0) + error("-%c option: bad left pane width %s: %s\n", + opt, lpane, err); + } + + if (rpane) { + if ((pw.vsplit2 = getznn(rpane, &err)) < 0) + error("-%c option: bad right pane width %s: %s\n", + opt, rpane, err); + } + + if (vs2pos) { + if ((pw.vs2pos = getznn(vs2pos, &err)) < 0) + error("-%c option: bad right pane view offset %s: %s\n", + opt, vs2pos, err); + } + } + break; default: usage(); } @@ -961,6 +1005,8 @@ int main(int argc, char **argv) pw.columns = ws.ws_col; } + clipsplits(&pw); + ttyget(ttyfd, &tty_saved); tty_new = tty_saved; @@ -1365,6 +1411,12 @@ int main(int argc, char **argv) case ctrl('l'): pw.stat |= stat_force; break; + case ctrl('g'): + snprintf(pw.cmdbuf, sizeof pw.cmdbuf, "-p %d,%d,%d,%d", + pw.hpos, pw.vsplit1, pw.vsplit2, pw.vs2pos); + pw.curcmd = pw.cmdbuf; + kbd_state = kbd_result; + break; case '0': if (cmdcount == UINT_MAX) { pw.hpos = 0; |