libsmartcols: support simplified color sequences
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
208480c4ba
commit
b48ef54b43
3 changed files with 18 additions and 9 deletions
|
@ -166,10 +166,13 @@ int scols_cmpstr_cells(struct libscols_cell *a,
|
||||||
*/
|
*/
|
||||||
int scols_cell_set_color(struct libscols_cell *ce, const char *color)
|
int scols_cell_set_color(struct libscols_cell *ce, const char *color)
|
||||||
{
|
{
|
||||||
if (color && isalpha(*color)) {
|
if (color && !color_is_sequence(color)) {
|
||||||
color = color_sequence_from_colorname(color);
|
char *seq = color_get_sequence(color);
|
||||||
if (!color)
|
if (!seq)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
free(ce->color);
|
||||||
|
ce->color = seq;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return strdup_to_struct_member(ce, color, color);
|
return strdup_to_struct_member(ce, color, color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
int scols_column_set_color(struct libscols_column *cl, const char *color)
|
||||||
{
|
{
|
||||||
if (color && isalpha(*color)) {
|
if (color && !color_is_sequence(color)) {
|
||||||
color = color_sequence_from_colorname(color);
|
char *seq = color_get_sequence(color);
|
||||||
if (!color)
|
if (!seq)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
free(cl->color);
|
||||||
|
cl->color = seq;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return strdup_to_struct_member(cl, color, color);
|
return strdup_to_struct_member(cl, color, color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
int scols_line_set_color(struct libscols_line *ln, const char *color)
|
||||||
{
|
{
|
||||||
if (color && isalnum(*color)) {
|
if (color && !color_is_sequence(color)) {
|
||||||
color = color_sequence_from_colorname(color);
|
char *seq = color_get_sequence(color);
|
||||||
if (!color)
|
if (!seq)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
free(ln->color);
|
||||||
|
ln->color = seq;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return strdup_to_struct_member(ln, color, color);
|
return strdup_to_struct_member(ln, color, color);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue