Add support for the -passes option to the ref highlighter
This commit is contained in:
parent
6b518e4e46
commit
9300a981eb
|
@ -1375,15 +1375,8 @@ private:
|
||||||
const String m_option_name;
|
const String m_option_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
HighlightPass parse_passes(StringView str)
|
||||||
{
|
{
|
||||||
static const ParameterDesc param_desc{
|
|
||||||
{ { "passes", { true, "" } } },
|
|
||||||
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
|
|
||||||
};
|
|
||||||
ParametersParser parser{params, param_desc};
|
|
||||||
|
|
||||||
auto parse_passes = [](StringView str) {
|
|
||||||
HighlightPass passes{};
|
HighlightPass passes{};
|
||||||
for (auto pass : str | split<StringView>('|'))
|
for (auto pass : str | split<StringView>('|'))
|
||||||
{
|
{
|
||||||
|
@ -1400,7 +1393,15 @@ HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
||||||
throw runtime_error{"no passes specified"};
|
throw runtime_error{"no passes specified"};
|
||||||
|
|
||||||
return passes;
|
return passes;
|
||||||
|
}
|
||||||
|
|
||||||
|
HighlighterAndId create_highlighter_group(HighlighterParameters params)
|
||||||
|
{
|
||||||
|
static const ParameterDesc param_desc{
|
||||||
|
{ { "passes", { true, "" } } },
|
||||||
|
ParameterDesc::Flags::SwitchesOnlyAtStart, 1, 1
|
||||||
};
|
};
|
||||||
|
ParametersParser parser{params, param_desc};
|
||||||
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