From: Karel Zak Date: Mon, 27 Feb 2023 16:50:39 +0000 (+0100) Subject: libsmartcols: support simplified color sequences X-Git-Tag: v2.39-rc1~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b48ef54b4380d40a7b1845fe17942c629c3df7cc;p=thirdparty%2Futil-linux.git libsmartcols: support simplified color sequences Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c index ca2a2b6394..5b831235b4 100644 --- a/libsmartcols/src/cell.c +++ b/libsmartcols/src/cell.c @@ -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); } diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index 8ebfa1ea27..db4c3572df 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -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); } diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c index a5d39b41b1..cab99c51da 100644 --- a/libsmartcols/src/line.c +++ b/libsmartcols/src/line.c @@ -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); }