summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2017-12-12 13:19:36 +0100
committerKarel Zak2017-12-12 13:19:36 +0100
commit3fa48b118adcfbfb1a45e9e1c62176fcdab900d8 (patch)
tree3cffb017e69fd92defc45d547946fa344e9d3ee8 /libsmartcols
parentsample-scols-title: add left title without padding (diff)
downloadkernel-qcow2-util-linux-3fa48b118adcfbfb1a45e9e1c62176fcdab900d8.tar.gz
kernel-qcow2-util-linux-3fa48b118adcfbfb1a45e9e1c62176fcdab900d8.tar.xz
kernel-qcow2-util-linux-3fa48b118adcfbfb1a45e9e1c62176fcdab900d8.zip
libsmartcols: don't add blank padding after left aligned title
Let's use the same semantic for the title as for the last column in the table. If aligned on left, table is not "maxout" and title padding symbol is undefined (or blank) then keep title as short as possible. Addresses: https://github.com/karelzak/util-linux/issues/549 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/table_print.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 6acaf9b4e..2e1c55ee1 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -761,7 +761,7 @@ static int print_title(struct libscols_table *tb)
{
int rc, color = 0;
mbs_align_t align;
- size_t width, bufsz, titlesz;
+ size_t width, len = 0, bufsz, titlesz;
char *title = NULL, *buf = NULL;
assert(tb);
@@ -773,7 +773,7 @@ static int print_title(struct libscols_table *tb)
/* encode data */
if (tb->no_encode) {
- bufsz = strlen(tb->title.data) + 1;
+ len = bufsz = strlen(tb->title.data) + 1;
buf = strdup(tb->title.data);
if (!buf) {
rc = -ENOMEM;
@@ -791,8 +791,8 @@ static int print_title(struct libscols_table *tb)
goto done;
}
- if (!mbs_safe_encode_to_buffer(tb->title.data, &bufsz, buf, NULL) ||
- !bufsz || bufsz == (size_t) -1) {
+ if (!mbs_safe_encode_to_buffer(tb->title.data, &len, buf, NULL) ||
+ !len || len == (size_t) -1) {
rc = -EINVAL;
goto done;
}
@@ -818,6 +818,14 @@ static int print_title(struct libscols_table *tb)
case SCOLS_CELL_FL_LEFT:
default:
align = MBS_ALIGN_LEFT;
+ /*
+ * Don't print extra blank chars after the title if on left
+ * (that's same as we use for the last column in the table).
+ */
+ if (len < width
+ && !scols_table_is_maxout(tb)
+ && isblank(*titlepadding_symbol(tb)))
+ width = len;
break;
}