Support info markup spanning multiple lines

Preserve the active face accross lines

Fixes #4313
This commit is contained in:
Maxime Coste 2021-08-28 13:53:01 +10:00
parent e454b393cf
commit 726bec4670
3 changed files with 18 additions and 7 deletions

View File

@ -2299,11 +2299,7 @@ const CommandDesc info_cmd = {
auto title = parser.get_switch("title").value_or(StringView{}); auto title = parser.get_switch("title").value_or(StringView{});
if (parser.get_switch("markup")) if (parser.get_switch("markup"))
context.client().info_show(parse_display_line(title, context.faces()), context.client().info_show(parse_display_line(title, context.faces()),
parser[0] | split<StringView>('\n') parse_display_line_list(parser[0], context.faces()),
| transform([&](StringView s) {
return parse_display_line(s, context.faces());
})
| gather<DisplayLineList>(),
pos, style); pos, style);
else else
context.client().info_show(title.str(), parser[0], pos, style); context.client().info_show(title.str(), parser[0], pos, style);

View File

@ -257,13 +257,12 @@ void DisplayBuffer::optimize()
line.optimize(); line.optimize();
} }
DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins) DisplayLine parse_display_line(StringView line, Face& face, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins)
{ {
DisplayLine res; DisplayLine res;
bool was_antislash = false; bool was_antislash = false;
auto pos = line.begin(); auto pos = line.begin();
String content; String content;
Face face;
for (auto it = line.begin(), end = line.end(); it != end; ++it) for (auto it = line.begin(), end = line.end(); it != end; ++it)
{ {
const char c = *it; const char c = *it;
@ -332,4 +331,19 @@ DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const
return res; return res;
} }
DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins)
{
Face face{};
return parse_display_line(line, face, faces, builtins);
}
DisplayLineList parse_display_line_list(StringView content, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins)
{
return content | split<StringView>('\n')
| transform([&, face=Face{}](StringView s) mutable {
return parse_display_line(s, face, faces, builtins);
})
| gather<DisplayLineList>();
}
} }

View File

@ -157,6 +157,7 @@ using DisplayLineList = Vector<DisplayLine>;
class FaceRegistry; class FaceRegistry;
DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins = {}); DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins = {});
DisplayLineList parse_display_line_list(StringView content, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins = {});
class DisplayBuffer : public UseMemoryDomain<MemoryDomain::Display> class DisplayBuffer : public UseMemoryDomain<MemoryDomain::Display>
{ {