*-t, --table*::
Determine the number of columns the input contains and create a table. Columns are by default delimited with whitespace, or with characters supplied using the *--output-separator* option. Table output is useful for pretty-printing.
+*--table-colorscheme* _name_::
+Specifies color scheme. The default is name is "column". For more details see the *COLORS* section.
+
*-C, --table-column* _attributes_::
Define a column with a comma-separated list of attributes.
This option can be used more than once, every use defines a single column.
lightblue, lightcyan, lightgray, lightgreen, lightmagenta, lightred, magenta,
red, reset, reverse, and yellow) or ANSI color sequence number(s) separated by
a semicolon, but without the 'ESC[' prefix and 'm' suffix. For example, "37;41"
-defines sequences for a red background and white foreground.
+defines sequences for a red background and white foreground. For more details
+see the *COLORS* section.
+**colorkey=**_name_;;
+Addresses color as defined in the color scheme. See *--table-colorscheme*.
+**headercolor=**_name_;;
+Like color=, but define the color for column header only.
+**headercolorkey=**_name_;;
+Addresses color for header as defined in the color scheme. See *--table-colorscheme*.
*-N, --table-columns* _names_::
Specify column names with a comma-separated list. The names are used for the table header
include::man-common/colors.adoc[]
+The default color scheme name is "column," and it can be overridden by
+____
+*--table-colorscheme name*
+____
+
+Then _name_[.disable|enable|scheme] file may be used in /etc/terminal-colors.d/,
+$XDG_CONFIG_HOME/terminal-colors.d, or $HOME/.config/terminal-colors.d/.
+
+The logical color name (key) in the color scheme may be addressed by column properties
+colorkey= and headercolorkey=. For example
+
+....
+echo 'important red' > ~/.config/terminal-colors.d/cooltable.scheme
+echo 'important-header 37;41' >> ~/.config/terminal-colors.d/cooltable.scheme
+echo -e "a b c\naa bb cc\naaa bbb ccc" | column -t \
+ --table-colorscheme=cooltable \
+ -C name=AAA,colorkey=important,headercolorkey=important-header \
+ -C name=BBB,color=magenta,headercolor=cyan \
+ -C name=CCC,color=green
+....
+
+This will create a color scheme with the name "cooltable" and colorize the first
+column header and data according to keys from the scheme. The other two columns
+will be colorized by direct color names.
+
== ENVIRONMENT
The environment variable *COLUMNS* is used to determine the size of the screen if no other information is available.
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;
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);
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) {
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);
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[] =
{ "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' },
if (optarg)
colormode = colormode_or_err(optarg);
break;
+ case OPT_COLORSCHEME:
+ ctl.tab_colorscheme = optarg;
+ break;
case 'h':
usage();
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);