summaryrefslogtreecommitdiff
path: root/libsmartcols
diff options
context:
space:
mode:
authorOndrej Oprala <ooprala@redhat.com>2014-03-24 13:40:05 +0100
committerKarel Zak <kzak@redhat.com>2014-04-03 12:29:17 +0200
commit35958d0c61cff969506a4ab1a15e1e28c7a60f77 (patch)
tree0646510949b0b4f4a3b058a2092f39ae18a812a7 /libsmartcols
parent8a38a8d31edc23db15eb031193df14da66dcdaff (diff)
downloadutil-linux-35958d0c61cff969506a4ab1a15e1e28c7a60f77.tar.gz
libsmartcols: colors may now be specified as human-readable strings
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/cell.c7
-rw-r--r--libsmartcols/src/column.c7
-rw-r--r--libsmartcols/src/line.c7
-rw-r--r--libsmartcols/src/test.c2
4 files changed, 22 insertions, 1 deletions
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c
index 5e3ea6081..fb523f013 100644
--- a/libsmartcols/src/cell.c
+++ b/libsmartcols/src/cell.c
@@ -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;
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index 5fad5319f..29eb63666 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -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;
diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c
index b982fba6d..ec5add3fb 100644
--- a/libsmartcols/src/line.c
+++ b/libsmartcols/src/line.c
@@ -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;
diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c
index 547a5fd00..0899cea31 100644
--- a/libsmartcols/src/test.c
+++ b/libsmartcols/src/test.c
@@ -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);