Add a -passes switch support for the group highlighter

This commit is contained in:
Maxime Coste 2017-05-04 12:16:38 +01:00
parent fa5ae65f3a
commit bb17fb6dd3

View File

@ -1288,10 +1288,33 @@ HighlighterAndId create_ranges_highlighter(HighlighterParameters params)
HighlighterAndId create_highlighter_group(HighlighterParameters params) HighlighterAndId create_highlighter_group(HighlighterParameters params)
{ {
if (params.size() != 1) static const ParameterDesc param_desc{
throw runtime_error("wrong parameter count"); { { "passes", { true, "" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
};
ParametersParser parser{params, param_desc};
return HighlighterAndId(params[0], make_unique<HighlighterGroup>(HighlightPass::Colorize)); auto parse_passes = [](StringView str) {
HighlightPass passes{};
for (auto pass : str | split<StringView>('|'))
{
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<HighlighterGroup>(passes));
} }
HighlighterAndId create_reference_highlighter(HighlighterParameters params) HighlighterAndId create_reference_highlighter(HighlighterParameters params)