]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: allow to change cell padding char
authorKarel Zak <kzak@redhat.com>
Wed, 7 Sep 2016 09:07:04 +0000 (11:07 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Sep 2016 09:07:04 +0000 (11:07 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/smartcolsP.h
libsmartcols/src/symbols.c
libsmartcols/src/table.c
libsmartcols/src/table_print.c

index e752e7056799c1d33ebc24e2faded26e46d3359a..f2bbbf38fcd0777f81b65fe26e7f3c3d4796a8db 100644 (file)
@@ -86,6 +86,7 @@ scols_symbols_set_branch
 scols_symbols_set_right
 scols_symbols_set_vertical
 scols_symbols_set_title_padding
+scols_symbols_set_cell_padding
 scols_unref_symbols
 </SECTION>
 
index 02867e2f5dfd981307ff8a071e499d46aef579a5..1165e0c2def25a6b9738fdef6bd43809b4d43100 100644 (file)
@@ -118,6 +118,7 @@ extern int scols_symbols_set_branch(struct libscols_symbols *sb, const char *str
 extern int scols_symbols_set_vertical(struct libscols_symbols *sb, const char *str);
 extern int scols_symbols_set_right(struct libscols_symbols *sb, const char *str);
 extern int scols_symbols_set_title_padding(struct libscols_symbols *sb, const char *str);
+extern int scols_symbols_set_cell_padding(struct libscols_symbols *sb, const char *str);
 
 /* cell.c */
 extern int scols_reset_cell(struct libscols_cell *ce);
index 9a4997dd866088c6f8f3c44e4d0ae9d0af5e1b7e..7b2cb88bb4250ebcef72919dbc45d570258f41c8 100644 (file)
@@ -140,4 +140,5 @@ global:
 SMARTCOLS_2.29 {
 global:
        scols_column_is_wrapnl;
+       scols_symbols_set_cell_padding;
 } SMARTCOLS_2.28;
index b3c8e7cfaa4a09aac3efa989f32e95a1377c2f4d..c1bb1e07f76a17fc09910a4dae4eec398e89a81a 100644 (file)
@@ -54,6 +54,7 @@ struct libscols_symbols {
        char    *vert;
        char    *right;
        char    *title_padding;
+       char    *cell_padding;
 };
 
 /*
index df31f454c07446cbfd2034f9a854ef554bfb67f7..d2f7a71ba19d1a24d465ed6d9c08027eed54c6a2 100644 (file)
@@ -106,7 +106,7 @@ int scols_symbols_set_right(struct libscols_symbols *sb, const char *str)
 /**
  * scols_symbols_set_title_padding:
  * @sb: a pointer to a struct libscols_symbols instance
- * @str: a string which will represent the symbols which wraps title output
+ * @str: a string which will represent the symbols which fill title output
  *
  * The current implementation uses only the first byte from the padding string.
  * A multibyte chars are not supported yet.
@@ -120,6 +120,22 @@ int scols_symbols_set_title_padding(struct libscols_symbols *sb, const char *str
        return strdup_to_struct_member(sb, title_padding, str);
 }
 
+/**
+ * scols_symbols_set_cell_padding:
+ * @sb: a pointer to a struct libscols_symbols instance
+ * @str: a string which will represent the symbols which fill cells
+ *
+ * The padding char has to take up just one cell on the terminal.
+ *
+ * Returns: 0, a negative value in case of an error.
+ *
+ * Since: 2.29
+ */
+int scols_symbols_set_cell_padding(struct libscols_symbols *sb, const char *str)
+{
+       return strdup_to_struct_member(sb, cell_padding, str);
+}
+
 /**
  * scols_copy_symbols:
  * @sb: a pointer to a struct libscols_symbols instance
@@ -146,6 +162,8 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb)
                rc = scols_symbols_set_right(ret, sb->right);
        if (!rc)
                rc = scols_symbols_set_title_padding(ret, sb->title_padding);
+       if (!rc)
+               rc = scols_symbols_set_cell_padding(ret, sb->cell_padding);
        if (!rc)
                return ret;
 
index 00188fb69ef8d74b1523d9041d723c1cabd94c96..dc3a3016c7e0e7cb1f1ce1a86602ddb257b27c4c 100644 (file)
@@ -695,6 +695,7 @@ int scols_table_set_symbols(struct libscols_table *tb,
                        scols_symbols_set_right(tb->symbols, "`-");
                }
                scols_symbols_set_title_padding(tb->symbols, " ");
+               scols_symbols_set_cell_padding(tb->symbols, " ");
        }
 
        return 0;
index 32b9ddab150cfd34c8c9f4a947df5f7834129b13..69ee32689baf30864b057fc6f7024f307b25270d 100644 (file)
 #include "carefulputc.h"
 #include "smartcolsP.h"
 
+#define colsep(tb)     ((tb)->colsep ? (tb)->colsep : " ")
+#define linesep(tb)    ((tb)->linesep ? (tb)->linesep : "\n")
+#define cellpadding(tb)        ((tb) && (tb)->symbols && (tb)->symbols->cell_padding ? (tb)->symbols->cell_padding : " ")
+
+
 /* This is private struct to work with output data */
 struct libscols_buffer {
        char    *begin;         /* begin of the buffer */
@@ -190,9 +195,6 @@ static int is_last_column(struct libscols_column *cl)
        return 0;
 }
 
-#define colsep(tb) ((tb)->colsep ? (tb)->colsep : " ")
-#define linesep(tb) ((tb)->linesep ? (tb)->linesep : "\n")
-
 
 static int has_pending_data(struct libscols_table *tb)
 {
@@ -248,7 +250,7 @@ static void print_empty_cell(struct libscols_table *tb,
 
        /* fill rest of cell with space */
        for(; len_pad < cl->width; ++len_pad)
-               fputc(' ', tb->out);
+               fputs(cellpadding(tb), tb->out);
 
        fputs(colsep(tb), tb->out);
 }
@@ -393,7 +395,7 @@ static int print_pending_data(
                return 0;
 
        for (i = len; i < width; i++)
-               fputc(' ', tb->out);            /* padding */
+               fputs(cellpadding(tb), tb->out);                /* padding */
 
        fputs(colsep(tb), tb->out);     /* columns separator */
        return 0;
@@ -505,7 +507,7 @@ static int print_data(struct libscols_table *tb,
                        if (color)
                                fputs(color, tb->out);
                        for (i = len; i < width; i++)
-                               fputc(' ', tb->out);
+                               fputs(cellpadding(tb), tb->out);
                        fputs(data, tb->out);
                        if (color)
                                fputs(UL_COLOR_RESET, tb->out);
@@ -528,7 +530,7 @@ static int print_data(struct libscols_table *tb,
                        fputs(data, tb->out);
        }
        for (i = len; i < width; i++)
-               fputc(' ', tb->out);            /* padding */
+               fputs(cellpadding(tb), tb->out);        /* padding */
 
        if (is_last_column(cl))
                return 0;