]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: support simplified color sequences
authorKarel Zak <kzak@redhat.com>
Mon, 27 Feb 2023 16:50:39 +0000 (17:50 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Feb 2023 16:50:39 +0000 (17:50 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/cell.c
libsmartcols/src/column.c
libsmartcols/src/line.c

index ca2a2b6394ed9d5fedc6ae9b1e0afe57503d1751..5b831235b4a73e563442d055a5931909864f3d86 100644 (file)
@@ -166,10 +166,13 @@ int scols_cmpstr_cells(struct libscols_cell *a,
  */
 int scols_cell_set_color(struct libscols_cell *ce, const char *color)
 {
-       if (color && isalpha(*color)) {
-               color = color_sequence_from_colorname(color);
-               if (!color)
+       if (color && !color_is_sequence(color)) {
+               char *seq = color_get_sequence(color);
+               if (!seq)
                        return -EINVAL;
+               free(ce->color);
+               ce->color = seq;
+               return 0;
        }
        return strdup_to_struct_member(ce, color, color);
 }
index 8ebfa1ea27cb0d8e70faa21a330e411a39654b9b..db4c3572df1e430cb743f212e815cd24de3cd05d 100644 (file)
@@ -339,10 +339,13 @@ const char *scols_column_get_name_as_shellvar(struct libscols_column *cl)
  */
 int scols_column_set_color(struct libscols_column *cl, const char *color)
 {
-       if (color && isalpha(*color)) {
-               color = color_sequence_from_colorname(color);
-               if (!color)
+       if (color && !color_is_sequence(color)) {
+               char *seq = color_get_sequence(color);
+               if (!seq)
                        return -EINVAL;
+               free(cl->color);
+               cl->color = seq;
+               return 0;
        }
        return strdup_to_struct_member(cl, color, color);
 }
index a5d39b41b1e7394faa7468d93d46ac68144d72c6..cab99c51dad3cb9f9f2718376ff7d3f520df2400 100644 (file)
@@ -364,10 +364,13 @@ int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *paren
  */
 int scols_line_set_color(struct libscols_line *ln, const char *color)
 {
-       if (color && isalnum(*color)) {
-               color = color_sequence_from_colorname(color);
-               if (!color)
+       if (color && !color_is_sequence(color)) {
+               char *seq = color_get_sequence(color);
+               if (!seq)
                        return -EINVAL;
+               free(ln->color);
+               ln->color = seq;
+               return 0;
        }
        return strdup_to_struct_member(ln, color, color);
 }