]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: colors may now be specified as human-readable strings
authorOndrej Oprala <ooprala@redhat.com>
Mon, 24 Mar 2014 12:40:05 +0000 (13:40 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:17 +0000 (12:29 +0200)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
libsmartcols/src/cell.c
libsmartcols/src/column.c
libsmartcols/src/line.c
libsmartcols/src/test.c

index 5e3ea6081bc37b66f191836d3b77e0be15e7ef1a..fb523f0137dcea5e0f325e273a8bf18572143f3d 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "smartcolsP.h"
 
@@ -85,6 +86,12 @@ int scols_cell_set_color(struct libscols_cell *ce, const char *color)
        if (!ce)
                return -EINVAL;
        if (color) {
+               if (isalnum(*color)) {
+                       color = colorscheme_from_string(color);
+
+                       if (!color)
+                               return -EINVAL;
+               }
                p = strdup(color);
                if (!p)
                        return -ENOMEM;
index 5fad5319fcb79fdcc1e7344b0b4d98b2b00a92ba..29eb636664253f00f3f13b010bdeaa745aacf627 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "smartcolsP.h"
 
@@ -118,6 +119,12 @@ int scols_column_set_color(struct libscols_column *cl, const char *color)
        if (!cl)
                return -EINVAL;
        if (color) {
+               if (isalnum(*color)) {
+                       color = colorscheme_from_string(color);
+
+                       if (!color)
+                               return -EINVAL;
+               }
                p = strdup(color);
                if (!p)
                        return -ENOMEM;
index b982fba6d8a6df814906fc5cce7247dc86bd16fe..ec5add3fb9a56161c85ef24ac9751e6f25356512 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "smartcolsP.h"
 
@@ -196,6 +197,12 @@ int scols_line_set_color(struct libscols_line *ln, const char *color)
        if (!ln)
                return -EINVAL;
        if (color) {
+               if (isalnum(*color)) {
+                       color = colorscheme_from_string(color);
+
+                       if (!color)
+                               return -EINVAL;
+               }
                p = strdup(color);
                if (!p)
                        return -ENOMEM;
index 547a5fd0035ecdd2d035e03b014414159a8191ac..0899cea3112c6b5701c78720fa1f944c73dc66de 100644 (file)
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
                struct libscols_cell *h = scols_column_get_header(cl);
 
                scols_column_set_color(cl, UL_COLOR_BOLD_GREEN);
-               scols_cell_set_color(h, UL_COLOR_GREEN);
+               scols_cell_set_color(h, "green"); /* a human-readable string is also legal */
        }
        scols_table_new_column(tb, "BAR", 0.3);
        scols_table_new_column(tb, "PATH", 0.3);