diff options
author | Craig Sanders <[email protected]> | 2012-03-27 21:37:41 +1100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2012-03-27 15:01:08 -0700 |
commit | 9fc60702c6679803c77939db732c294b6b6952d2 (patch) | |
tree | edb78d70f78ff307661e2f5d55668dabf5378d9b /cmd | |
parent | 2008ab88dd19ae3947b30b4e933fbf2273300aa2 (diff) |
Remove hard-coded 80 column output
When stdout is detected to be a tty use the number of columns
specified by the terminal. If that fails fall back to a default
80 column width. In the non-tty case allow for 999 column lines.
Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zpool/zpool_main.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 9e73ddaff..5dbb11935 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -2175,11 +2175,30 @@ print_iostat(zpool_handle_t *zhp, void *data) return (0); } +static int +get_columns(void) +{ + struct winsize ws; + int columns = 80; + int error; + + if (isatty(STDOUT_FILENO)) { + error = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws); + if (error == 0) + columns = ws.ws_col; + } else { + columns = 999; + } + + return columns; +} + int get_namewidth(zpool_handle_t *zhp, void *data) { iostat_cbdata_t *cb = data; nvlist_t *config, *nvroot; + int columns; if ((config = zpool_get_config(zhp, NULL)) != NULL) { verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, @@ -2191,13 +2210,15 @@ get_namewidth(zpool_handle_t *zhp, void *data) } /* - * The width must fall into the range [10,38]. The upper limit is the - * maximum we can have and still fit in 80 columns. + * The width must be at least 10, but may be as large as the + * column width - 42 so that we can still fit in one line. */ + columns = get_columns(); + if (cb->cb_namewidth < 10) cb->cb_namewidth = 10; - if (cb->cb_namewidth > 38) - cb->cb_namewidth = 38; + if (cb->cb_namewidth > columns - 42) + cb->cb_namewidth = columns - 42; return (0); } |