highlight: Add colorize_shell wrapper

Since we don't reuse the vector anyway, this allows us to keep the
highlighting on the C++-side.
This commit is contained in:
Fabian Boehm
2023-04-10 19:49:08 +02:00
parent 31d65de26c
commit d02d0f3309
2 changed files with 12 additions and 0 deletions

View File

@@ -32,6 +32,7 @@
#include "output.h"
#include "parse_constants.h"
#include "parse_util.h"
#include "parser.h"
#include "path.h"
#include "redirection.h"
#include "tokenizer.h"
@@ -1372,3 +1373,9 @@ void highlight_shell(const wcstring &buff, std::vector<highlight_spec_t> &color,
highlighter_t highlighter(buff, cursor, ctx, working_directory, io_ok);
color = highlighter.highlight();
}
wcstring colorize_shell(const wcstring &text, parser_t &parser) {
std::vector<highlight_spec_t> colors;
highlight_shell(text, colors, parser.context());
return str2wcstring(colorize(text, colors, parser.vars()));
}

View File

@@ -111,6 +111,11 @@ void highlight_shell(const wcstring &buffstr, std::vector<highlight_spec_t> &col
const operation_context_t &ctx, bool io_ok = false,
maybe_t<size_t> cursor = {});
class parser_t;
/// Wrapper around colorize(highlight_shell)
wcstring colorize_shell(const wcstring &text, parser_t &parser);
/// highlight_color_resolver_t resolves highlight specs (like "a command") to actual RGB colors.
/// It maintains a cache with no invalidation mechanism. The lifetime of these should typically be
/// one screen redraw.