From: Karel Zak Date: Mon, 27 Jul 2015 13:29:37 +0000 (+0200) Subject: cfdisk: make sure that output fits to terminal width X-Git-Tag: v2.27-rc1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed99eac0e2a83a315c7cf5d8a461df16b3106596;p=thirdparty%2Futil-linux.git cfdisk: make sure that output fits to terminal width Reported-by: Benno Schulenberg Signed-off-by: Karel Zak --- diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index e3eeab58b2..aca1f9cffd 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -497,12 +497,23 @@ static int lines_refresh(struct cfdisk *cf) cf->lines = xcalloc(cf->nlines, sizeof(struct cfdisk_line)); for (p = cf->linesbuf, i = 0; p && i < cf->nlines; i++) { - cf->lines[i].data = p; - p = strchr(p, '\n'); + char *begin = p; + size_t sz; + + cf->lines[i].data = begin; + p = strchr(begin, '\n'); + sz = p ? (size_t) (p - begin) : strlen(begin); if (p) { *p = '\0'; p++; } + /* libsmartcols reduces columns width as much as possible to + * fit terminal width, but for very small terminals it preffers + * long lines rather than remove columns from output. This is fine + * for normal utils, but it's problematic for ncurses -- so we + * manually cut the end of the line to fit terminal width. */ + if (sz + ARROW_CURSOR_WIDTH > ui_cols) + *(begin + (ui_cols - ARROW_CURSOR_WIDTH)) = '\0'; cf->lines[i].extra = scols_new_table(); scols_table_enable_noheadings(cf->lines[i].extra, 1); scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_RIGHT);