#if ENABLE_FEATURE_AUTOWIDTH
/* Obtain the terminal width */
- get_terminal_width_height(STDOUT_FILENO, &terminal_width, NULL);
+ get_terminal_width_height(STDIN_FILENO, &terminal_width, NULL);
/* Go one less... */
terminal_width--;
#endif
extern int update_passwd(const char *filename, const char *username,
const char *new_pw);
-int get_terminal_width_height(const int fd, int *width, int *height);
+/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
+int get_terminal_width_height(int fd, int *width, int *height);
int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
/* It is perfectly ok to pass in a NULL for either width or for
* height, in which case that value will not be set. */
-int get_terminal_width_height(const int fd, int *width, int *height)
+int get_terminal_width_height(int fd, int *width, int *height)
{
struct winsize win = { 0, 0, 0, 0 };
int ret = ioctl(fd, TIOCGWINSZ, &win);
* and such large widths */
terminal_width = MAX_WIDTH;
if (isatty(1)) {
- get_terminal_width_height(1, &terminal_width, NULL);
+ get_terminal_width_height(0, &terminal_width, NULL);
if (--terminal_width > MAX_WIDTH)
terminal_width = MAX_WIDTH;
}
if (w_count) {
terminal_width = (w_count==1) ? 132 : MAX_WIDTH;
} else {
- get_terminal_width_height(1, &terminal_width, NULL);
+ get_terminal_width_height(0, &terminal_width, NULL);
/* Go one less... */
if (--terminal_width > MAX_WIDTH)
terminal_width = MAX_WIDTH;
{
unsigned opt;
unsigned period = 2;
- unsigned cmdlen = 1; // 1 for terminal NUL
+ unsigned cmdlen;
char *header = NULL;
char *cmd;
char *tmp;
argv += optind;
p = argv;
+ cmdlen = 1; // 1 for terminal NUL
while (*p)
cmdlen += strlen(*p++) + 1;
tmp = cmd = xmalloc(cmdlen);
char *thyme;
time_t t;
- get_terminal_width_height(STDOUT_FILENO, &width, 0);
+ get_terminal_width_height(STDIN_FILENO, &width, 0);
header = xrealloc(header, width--);
// '%-*s' pads header with spaces to the full width
snprintf(header, width, "Every %ds: %-*s", period, width, cmd);