Colorize complete output

If interactive, `complete` commands are highlighted like they would
be if typed. Adds a little fun contrast and it's easier to read.

Moved a function out of fish_indent to highlight.h
This commit is contained in:
Aaron Gyes
2019-09-19 04:27:33 -07:00
parent 620761b9b9
commit cb79d8fa97
4 changed files with 35 additions and 22 deletions

View File

@@ -375,26 +375,6 @@ static wcstring prettify(const wcstring &src, bool do_indent) {
return std::move(prettifier.output);
}
/// Given a string and list of colors of the same size, return the string with ANSI escape sequences
/// representing the colors.
static std::string ansi_colorize(const wcstring &text,
const std::vector<highlight_spec_t> &colors) {
assert(colors.size() == text.size());
outputter_t outp;
highlight_spec_t last_color = highlight_role_t::normal;
for (size_t i = 0; i < text.size(); i++) {
highlight_spec_t color = colors.at(i);
if (color != last_color) {
outp.set_color(highlight_get_color(color, false), rgb_color_t::normal());
last_color = color;
}
outp.writech(text.at(i));
}
outp.set_color(rgb_color_t::normal(), rgb_color_t::normal());
return outp.contents();
}
/// Given a string and list of colors of the same size, return the string with HTML span elements
/// for the various colors.
static const wchar_t *html_class_name_for_color(highlight_spec_t spec) {
@@ -676,7 +656,7 @@ int main(int argc, char *argv[]) {
break;
}
case output_type_ansi: {
colored_output = ansi_colorize(output_wtext, colors);
colored_output = colorize(output_wtext, colors);
break;
}
case output_type_html: {