set_color: Print the given colors with --print-colors

This commit is contained in:
Fabian Boehm 2022-07-01 21:27:32 +02:00
parent 0a73b182c0
commit 98ba66ed8e
3 changed files with 16 additions and 4 deletions

View file

@ -32,7 +32,7 @@ The following options are available:
Sets the background color.
**-c** or **--print-colors**
Prints a list of the 16 named colors.
Prints the given colors or a colored list of the 16 named colors.
**-o** or **--bold**
Sets bold mode.

View file

@ -63,10 +63,11 @@ static void print_modifiers(outputter_t &outp, bool bold, bool underline, bool i
}
}
static void print_colors(io_streams_t &streams, bool bold, bool underline, bool italics, bool dim,
static void print_colors(io_streams_t &streams, wcstring_list_t args, bool bold, bool underline, bool italics, bool dim,
bool reverse, rgb_color_t bg) {
outputter_t outp;
for (const auto &color_name : rgb_color_t::named_color_names()) {
if (args.empty()) args = rgb_color_t::named_color_names();
for (const auto &color_name : args) {
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
print_modifiers(outp, bold, underline, italics, dim, reverse, bg);
rgb_color_t color = rgb_color_t(color_name);
@ -182,7 +183,8 @@ maybe_t<int> builtin_set_color(parser_t &parser, io_streams_t &streams, const wc
if (bgcolor && bg.is_special()) {
bg = rgb_color_t(L"");
}
print_colors(streams, bold, underline, italics, dim, reverse, bg);
wcstring_list_t args(argv + w.woptind, argv + argc);
print_colors(streams, args, bold, underline, italics, dim, reverse, bg);
return STATUS_CMD_OK;
}

View file

@ -82,3 +82,13 @@ expect_str("\n\x1b[37mwhite")
expect_str("\n\x1b[33myellow")
expect_str("normal")
expect_prompt()
# ENABLE RGB MODE - turn this off if you want to test anything after this!
sendline("set -g fish_term24bit 1")
expect_prompt()
# See that --print-colors prints the given colors.
sendline("set_color --print-colors ff0 red")
expect_str("\x1b[38;2;255;255;0mff0")
expect_str("\x1b[31mred")
expect_prompt()