From 98ba66ed8e4cfb6d3c3785da7ee41cb42552426e Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Fri, 1 Jul 2022 21:27:32 +0200 Subject: [PATCH] set_color: Print the given colors with --print-colors --- doc_src/cmds/set_color.rst | 2 +- src/builtins/set_color.cpp | 8 +++++--- tests/pexpects/set_color.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc_src/cmds/set_color.rst b/doc_src/cmds/set_color.rst index db1ba1796..81d5d4f36 100644 --- a/doc_src/cmds/set_color.rst +++ b/doc_src/cmds/set_color.rst @@ -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. diff --git a/src/builtins/set_color.cpp b/src/builtins/set_color.cpp index 5cb489652..26b16a9b1 100644 --- a/src/builtins/set_color.cpp +++ b/src/builtins/set_color.cpp @@ -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 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; } diff --git a/tests/pexpects/set_color.py b/tests/pexpects/set_color.py index a1e9676cc..d382cce4a 100644 --- a/tests/pexpects/set_color.py +++ b/tests/pexpects/set_color.py @@ -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()