diff options
Diffstat (limited to 'text-utils/column.c')
| -rw-r--r-- | text-utils/column.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/text-utils/column.c b/text-utils/column.c index 7a8b364150..0571c7463d 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -84,6 +84,7 @@ struct column_control { const char *tab_colnoextrem; /* --table-noextreme */ const char *tab_colwrap; /* --table-wrap */ const char *tab_colhide; /* --table-hide */ + const char *tab_colorscheme; /* --table-colorscheme */ const char *tree; const char *tree_id; @@ -331,6 +332,20 @@ static char **split_or_error(const char *str, const char *errmsg) return res; } +/* @key= is expected in the options string */ +static const char *colorseq_from_colorkey(char *opts, const char *key) +{ + char *cs = ul_optstr_get_value(opts, key); + const char *seq = NULL; + + if (cs) { + seq = color_scheme_get_sequence(cs, NULL); + free(cs); + } + + return seq; +} + static void init_table(struct column_control *ctl) { scols_init_debug(0); @@ -357,6 +372,18 @@ static void init_table(struct column_control *ctl) cl = scols_table_new_column(ctl->tab, NULL, 0, 0); scols_column_set_properties(cl, *opts); + + if (ctl->tab_colorscheme) { + const char *seq; + + seq = colorseq_from_colorkey(*opts, "colorkey"); + if (seq) + scols_column_set_color(cl, seq); + + seq = colorseq_from_colorkey(*opts, "headercolorkey"); + if (seq) + scols_column_set_headercolor(cl, seq); + } } } else if (ctl->tab_colnames) { @@ -901,6 +928,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -t, --table create a table\n"), out); fputs(_(" -n, --table-name <name> table name for JSON output\n"), out); fputs(_(" -O, --table-order <columns> specify order of output columns\n"), out); + fputs(_(" --table-colorscheme <name> specify color scheme name\n"), out); fputs(_(" -C, --table-column <properties> define column\n"), out); fputs(_(" -N, --table-columns <names> comma separated columns names\n"), out); fputs(_(" -l, --table-columns-limit <num> maximal number of input columns\n"), out); @@ -950,7 +978,8 @@ int main(int argc, char **argv) unsigned int eval = 0; /* exit value */ int colormode = UL_COLORMODE_UNDEF; enum { - OPT_COLOR = CHAR_MAX + 1 + OPT_COLOR = CHAR_MAX + 1, + OPT_COLORSCHEME, }; static const struct option longopts[] = @@ -965,6 +994,7 @@ int main(int argc, char **argv) { "output-width", required_argument, NULL, 'c' }, { "separator", required_argument, NULL, 's' }, { "table", no_argument, NULL, 't' }, + { "table-colorscheme", required_argument, NULL, OPT_COLORSCHEME }, { "table-columns", required_argument, NULL, 'N' }, { "table-column", required_argument, NULL, 'C' }, { "table-columns-limit", required_argument, NULL, 'l' }, @@ -1097,6 +1127,9 @@ int main(int argc, char **argv) if (optarg) colormode = colormode_or_err(optarg); break; + case OPT_COLORSCHEME: + ctl.tab_colorscheme = optarg; + break; case 'h': usage(); @@ -1129,7 +1162,7 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("option --table-columns or --table-column required for --json")); if (ctl.mode == COLUMN_MODE_TABLE) - colors_init(colormode, "column"); + colors_init(colormode, ctl.tab_colorscheme ? : "column"); if (!*argv) eval += read_input(&ctl, stdin); |
