mirror of
https://github.com/ericonr/util-linux.git
synced 2024-04-21 09:12:35 -05:00
cfdisk: make sure that output fits to terminal width
Reported-by: Benno Schulenberg <bensberg@justemail.net> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
5627fcec0e
commit
ed99eac0e2
@ -497,12 +497,23 @@ static int lines_refresh(struct cfdisk *cf)
|
|||||||
cf->lines = xcalloc(cf->nlines, sizeof(struct cfdisk_line));
|
cf->lines = xcalloc(cf->nlines, sizeof(struct cfdisk_line));
|
||||||
|
|
||||||
for (p = cf->linesbuf, i = 0; p && i < cf->nlines; i++) {
|
for (p = cf->linesbuf, i = 0; p && i < cf->nlines; i++) {
|
||||||
cf->lines[i].data = p;
|
char *begin = p;
|
||||||
p = strchr(p, '\n');
|
size_t sz;
|
||||||
|
|
||||||
|
cf->lines[i].data = begin;
|
||||||
|
p = strchr(begin, '\n');
|
||||||
|
sz = p ? (size_t) (p - begin) : strlen(begin);
|
||||||
if (p) {
|
if (p) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
p++;
|
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();
|
cf->lines[i].extra = scols_new_table();
|
||||||
scols_table_enable_noheadings(cf->lines[i].extra, 1);
|
scols_table_enable_noheadings(cf->lines[i].extra, 1);
|
||||||
scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_RIGHT);
|
scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_RIGHT);
|
||||||
|
Loading…
Reference in New Issue
Block a user