mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
builtin_set_color.cpp: colorize set_color --print-colors
Each named color is now printed in that color, only if hooked up to a TTY. Shouldn't affect scripts.
This commit is contained in:
parent
61f0756fe6
commit
5f05d9734c
1 changed files with 12 additions and 6 deletions
|
@ -34,12 +34,18 @@
|
|||
class parser_t;
|
||||
|
||||
static void print_colors(io_streams_t &streams) {
|
||||
const wcstring_list_t result = rgb_color_t::named_color_names();
|
||||
size_t i;
|
||||
for (i = 0; i < result.size(); i++) {
|
||||
streams.out.append(result.at(i));
|
||||
streams.out.push_back(L'\n');
|
||||
}
|
||||
outputter_t outp;
|
||||
|
||||
for (wcstring color_name : rgb_color_t::named_color_names()) {
|
||||
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
|
||||
rgb_color_t color = rgb_color_t(color_name);
|
||||
outp.set_color(color, rgb_color_t::none());
|
||||
}
|
||||
outp.writestr(color_name.c_str());
|
||||
outp.writech(L'\n');
|
||||
} // conveniently, 'normal' is always the last color so we don't need to reset here
|
||||
|
||||
streams.out.append(str2wcstring(outp.contents()));
|
||||
}
|
||||
|
||||
static const wchar_t *const short_options = L":b:hvoidrcu";
|
||||
|
|
Loading…
Reference in a new issue