From bb17fb6dd3efba7369745c9b1176392d9990bd28 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 4 May 2017 12:16:38 +0100 Subject: [PATCH] Add a `-passes` switch support for the group highlighter --- src/highlighters.cc | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 5c0f5806..48ff01f9 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1288,10 +1288,33 @@ HighlighterAndId create_ranges_highlighter(HighlighterParameters params) HighlighterAndId create_highlighter_group(HighlighterParameters params) { - if (params.size() != 1) - throw runtime_error("wrong parameter count"); + static const ParameterDesc param_desc{ + { { "passes", { true, "" } } }, + ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1 + }; + ParametersParser parser{params, param_desc}; - return HighlighterAndId(params[0], make_unique(HighlightPass::Colorize)); + auto parse_passes = [](StringView str) { + HighlightPass passes{}; + for (auto pass : str | split('|')) + { + if (pass == "colorize") + passes |= HighlightPass::Colorize; + else if (pass == "move") + passes |= HighlightPass::Move; + else if (pass == "wrap") + passes |= HighlightPass::Wrap; + else + throw runtime_error{format("invalid highlight pass: {}", pass)}; + } + if (passes == HighlightPass{}) + throw runtime_error{"no passes specified"}; + + return passes; + }; + HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize")); + + return HighlighterAndId(parser[0], make_unique(passes)); } HighlighterAndId create_reference_highlighter(HighlighterParameters params)