aboutsummaryrefslogtreecommitdiffhomepage
path: root/builtin_set_color.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-11-09 16:42:35 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-11-09 16:42:35 -0800
commite83441395e726a01abc8df95ac996d5b4bc2f364 (patch)
tree0c86dbb37b03a245d81ce77f36cd4545027cf3de /builtin_set_color.cpp
parent43d23ee56e76f07451f725d915f243808ab3784a (diff)
Make set_color take multiple colors, and choose the best supported one
As suggested in #1323
Diffstat (limited to 'builtin_set_color.cpp')
-rw-r--r--builtin_set_color.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp
index 1cce8097..b3757e1c 100644
--- a/builtin_set_color.cpp
+++ b/builtin_set_color.cpp
@@ -132,37 +132,31 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv)
}
}
- /* Remaining argument is foreground color */
- const wchar_t *fgcolor = NULL;
- if (woptind < argc)
+ /* Remaining arguments are foreground color */
+ std::vector<rgb_color_t> fgcolors;
+ for (; woptind < argc; woptind++)
{
- if (woptind + 1 == argc)
+ rgb_color_t fg = rgb_color_t(argv[woptind]);
+ if (fg.is_none() || fg.is_ignore())
{
- fgcolor = argv[woptind];
- }
- else
- {
- append_format(stderr_buffer,
- _(L"%ls: Too many arguments\n"),
- argv[0]);
+ append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], argv[woptind]);
return STATUS_BUILTIN_ERROR;
}
+ fgcolors.push_back(fg);
}
- if (fgcolor == NULL && bgcolor == NULL && !bold && !underline)
+ if (fgcolors.empty() && bgcolor == NULL && !bold && !underline)
{
append_format(stderr_buffer,
_(L"%ls: Expected an argument\n"),
argv[0]);
return STATUS_BUILTIN_ERROR;
}
-
- const rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : L"");
- if (fgcolor && (fg.is_none() || fg.is_ignore()))
- {
- append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], fgcolor);
- return STATUS_BUILTIN_ERROR;
- }
+
+ // #1323: We may have multiple foreground colors. Choose the best one.
+ // If we had no foreground coor, we'll get none(); if we have at least one we expect not-none
+ const rgb_color_t fg = best_color(fgcolors, output_get_color_support());
+ assert(fgcolors.empty() || !(fg.is_none() || fg.is_ignore()));
const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
if (bgcolor && (bg.is_none() || bg.is_ignore()))
@@ -187,7 +181,6 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv)
return STATUS_BUILTIN_ERROR;
}
-
/* Save old output function so we can restore it */
int (* const saved_writer_func)(char) = output_get_writer();
@@ -216,7 +209,7 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv)
}
}
- if (fgcolor != NULL)
+ if (! fg.is_none())
{
if (fg.is_normal() || fg.is_reset())
{