]> err.no Git - util-linux/commitdiff
lib: tt.c - fix minimal width of column
authorKarel Zak <kzak@redhat.com>
Fri, 16 Apr 2010 12:39:16 +0000 (14:39 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Jun 2010 13:20:12 +0000 (15:20 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/tt.h
lib/tt.c

index 8e2994f3756efae3bd860537ac46d13ff137435d..bf24d550ce3046eb4574c9372a1b0034ef15a7c6 100644 (file)
@@ -35,6 +35,7 @@ struct tt_column {
        int     seqnum;
 
        int     width;          /* real column width */
+       int     width_min;      /* minimal width (width of header) */
        double  width_hint;     /* hint (N < 1 is in percent of termwidth) */
 
        int     flags;
index cd65197090fbd0bd86ade060c1e4e2cc6462d64a..beb04311f641be23197b3e05f33a46a45b7fc7b6 100644 (file)
--- a/lib/tt.c
+++ b/lib/tt.c
@@ -388,6 +388,9 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
 
                        if (cl->width < len)
                                cl->width = len;
+
+fprintf(stderr, "KZAK: 1: %s = %d\n", cl->name, cl->width);
+
                }
        }
 
@@ -397,14 +400,18 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
                struct tt_column *cl =
                                list_entry(p, struct tt_column, cl_columns);
 
-               size_t len = mbs_width(cl->name);
+               cl->width_min = mbs_width(cl->name);
 
-               if (cl->width < len)
-                       cl->width = len;
-               else if (cl->width_hint >= 1)
+               if (cl->width < cl->width_min)
+                       cl->width = cl->width_min;
+               else if (cl->width_hint >= 1 &&
+                        cl->width_min < (int) cl->width_hint)
                        cl->width = (int) cl->width_hint;
 
                width += cl->width + (is_last_column(tb, cl) ? 0 : 1);
+
+fprintf(stderr, "KZAK: 2: %s = %d\n", cl->name, cl->width);
+
        }
 
        if (width == tb->termwidth)
@@ -438,6 +445,8 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
                                continue;       /* never truncate the tree */
                        if (trunc_only && !(cl->flags & TT_FL_TRUNCATE))
                                continue;
+                       if (cl->width == cl->width_min)
+                               continue;
                        if (cl->width > cl->width_hint * tb->termwidth) {
                                cl->width--;
                                width--;
@@ -451,7 +460,7 @@ static void recount_widths(struct tt *tb, char *buf, size_t bufsz)
                }
        }
 leave:
-/*
+///*
        fprintf(stderr, "terminal: %d, output: %d\n", tb->termwidth, width);
 
        list_for_each(p, &tb->tb_columns) {
@@ -463,7 +472,7 @@ leave:
                        cl->width_hint > 1 ? (int) cl->width_hint :
                                             (int) (cl->width_hint * tb->termwidth));
        }
-*/
+//*/
        return;
 }