w: Adjust command width

w would error out if the window size was smaller than 71 or some
other fields through environment grew too big. The code was a little
convoluted as well. The minimum length for command was 3, which is
pretty useless.

This change does the following:
 w doesn't care by default the window size
 w will adjust the command length up and down, to a minimum of 7
characters.
 if the fields don't fit, w will line-wrap each line.

The idea being its better the line-wrap than it is to error out.

References: https://bugs.debian.org/183394

Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
Craig Small 2015-07-21 22:45:02 +10:00
parent 857bb39d31
commit 151c05b497

12
w.c
View File

@ -70,6 +70,7 @@ typedef struct utmp utmp_t;
#endif #endif
#define MAX_CMD_WIDTH 512 #define MAX_CMD_WIDTH 512
#define MIN_CMD_WIDTH 7
/* /*
* This routine is careful since some programs leave utmp strings * This routine is careful since some programs leave utmp strings
@ -570,16 +571,11 @@ int main(int argc, char **argv)
maxcmd = atoi(p); maxcmd = atoi(p);
else else
maxcmd = MAX_CMD_WIDTH; maxcmd = MAX_CMD_WIDTH;
if (maxcmd < 71) if (MAX_CMD_WIDTH < maxcmd)
xerrx(EXIT_FAILURE, _("%d column window is too narrow"), maxcmd);
if (MAX_CMD_WIDTH < maxcmd) {
xwarnx(_("%d column width exceeds command buffer size, truncating to %d"),
maxcmd, MAX_CMD_WIDTH);
maxcmd = MAX_CMD_WIDTH; maxcmd = MAX_CMD_WIDTH;
}
maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0); maxcmd -= 21 + userlen + (from ? fromlen : 0) + (longform ? 20 : 0);
if (maxcmd < 3) if (maxcmd < MIN_CMD_WIDTH)
xwarnx(_("warning: screen width %d suboptimal"), win.ws_col); maxcmd = MIN_CMD_WIDTH;
procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT); procs = readproctab(PROC_FILLCOM | PROC_FILLUSR | PROC_FILLSTAT);