Add support for the -passes option to the ref highlighter
This commit is contained in:
parent
6b518e4e46
commit
9300a981eb
|
@ -1375,6 +1375,26 @@ private:
|
||||||
const String m_option_name;
|
const String m_option_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HighlightPass 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;
|
||||||
|
}
|
||||||
|
|
||||||
HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
||||||
{
|
{
|
||||||
static const ParameterDesc param_desc{
|
static const ParameterDesc param_desc{
|
||||||
|
@ -1382,25 +1402,6 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
||||||
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
|
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
|
||||||
};
|
};
|
||||||
ParametersParser parser{params, param_desc};
|
ParametersParser parser{params, param_desc};
|
||||||
|
|
||||||
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"));
|
HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize"));
|
||||||
|
|
||||||
return HighlighterAndId(parser[0], make_unique<HighlighterGroup>(passes));
|
return HighlighterAndId(parser[0], make_unique<HighlighterGroup>(passes));
|
||||||
|
@ -1408,14 +1409,14 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
||||||
|
|
||||||
HighlighterAndId create_reference_highlighter(HighlighterParameters params)
|
HighlighterAndId create_reference_highlighter(HighlighterParameters params)
|
||||||
{
|
{
|
||||||
if (params.size() != 1)
|
static const ParameterDesc param_desc{
|
||||||
throw runtime_error("wrong parameter count");
|
{ { "passes", { true, "" } } },
|
||||||
|
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
|
||||||
const String& name = params[0];
|
};
|
||||||
|
ParametersParser parser{params, param_desc};
|
||||||
// throw if not found
|
HighlightPass passes = parse_passes(parser.get_switch("passes").value_or("colorize"));
|
||||||
//DefinedHighlighters::instance().get_group(name, '/');
|
|
||||||
|
|
||||||
|
const String& name = parser[0];
|
||||||
auto func = [=](const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range)
|
auto func = [=](const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange range)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1425,8 +1426,7 @@ HighlighterAndId create_reference_highlighter(HighlighterParameters params)
|
||||||
catch (child_not_found&)
|
catch (child_not_found&)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
return {name, make_highlighter(func, passes)};
|
||||||
return {name, make_highlighter(func, HighlightPass::All)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RegexMatch
|
struct RegexMatch
|
||||||
|
@ -1905,8 +1905,10 @@ void register_highlighters()
|
||||||
registry.insert({
|
registry.insert({
|
||||||
"ref",
|
"ref",
|
||||||
{ create_reference_highlighter,
|
{ create_reference_highlighter,
|
||||||
"Parameters: <path>\n"
|
"Parameters: [-passes <passes>] <path>\n"
|
||||||
"Reference the highlighter at <path> in shared highglighters" } });
|
"Reference the highlighter at <path> in shared highglighters\n"
|
||||||
|
"<passes> is a flags(colorize|move|wrap) defaulting to colorize\n"
|
||||||
|
"which specify what kind of highlighters can be referenced" } });
|
||||||
registry.insert({
|
registry.insert({
|
||||||
"regions",
|
"regions",
|
||||||
{ RegionsHighlighter::create,
|
{ RegionsHighlighter::create,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user