From d02d0f330990d8bd7e66af63e098ee846de4ccf8 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Mon, 10 Apr 2023 19:49:08 +0200 Subject: [PATCH] highlight: Add colorize_shell wrapper Since we don't reuse the vector anyway, this allows us to keep the highlighting on the C++-side. --- src/highlight.cpp | 7 +++++++ src/highlight.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/highlight.cpp b/src/highlight.cpp index 89217f7a2..041a6e1f3 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -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 &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 colors; + highlight_shell(text, colors, parser.context()); + return str2wcstring(colorize(text, colors, parser.vars())); +} diff --git a/src/highlight.h b/src/highlight.h index 54bf41a9d..87be02a03 100644 --- a/src/highlight.h +++ b/src/highlight.h @@ -111,6 +111,11 @@ void highlight_shell(const wcstring &buffstr, std::vector &col const operation_context_t &ctx, bool io_ok = false, maybe_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.