Mercurial > dovecot > core-2.2
changeset 11534:2f3ce92f53ff HEAD
doveadm: Use actual terminal width for table formatter if possible.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 12 Jun 2010 01:54:53 +0100 |
parents | f35949b56863 |
children | c55de307d9f9 |
files | src/doveadm/doveadm-print-table.c |
diffstat | 1 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-print-table.c Sat Jun 12 01:49:06 2010 +0100 +++ b/src/doveadm/doveadm-print-table.c Sat Jun 12 01:54:53 2010 +0100 @@ -5,8 +5,11 @@ #include "doveadm-print-private.h" #include <stdio.h> +#include <unistd.h> +#include <sys/ioctl.h> #define DEFAULT_COLUMNS 80 +#define MIN_COLUMNS 30 #define MAX_BUFFER_LINES 100 struct doveadm_print_table_header { @@ -164,6 +167,7 @@ static void doveadm_print_table_init(void) { pool_t pool; + struct ttysize ts; pool = pool_alloconly_create("doveadm print table", 1024); ctx = p_new(pool, struct doveadm_print_table_context, 1); @@ -171,6 +175,11 @@ p_array_init(&ctx->headers, pool, 16); i_array_init(&ctx->buffered_values, 64); ctx->columns = DEFAULT_COLUMNS; + + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ts) == 0) { + ctx->columns = ts.ts_cols < MIN_COLUMNS ? + MIN_COLUMNS : ts.ts_cols; + } } static void doveadm_print_table_deinit(void)