Merge remote-tracking branch 'hristost/hristost/line-number-active-separator'

This commit is contained in:
Maxime Coste 2021-03-22 19:48:55 +11:00
commit 59ab4af57d

View File

@ -1082,11 +1082,12 @@ private:
struct LineNumbersHighlighter : Highlighter
{
LineNumbersHighlighter(bool relative, bool hl_cursor_line, String separator, int min_digits)
LineNumbersHighlighter(bool relative, bool hl_cursor_line, String separator, String separator_cursor, int min_digits)
: Highlighter{HighlightPass::Move},
m_relative{relative},
m_hl_cursor_line{hl_cursor_line},
m_separator{std::move(separator)},
m_separator_cursor{std::move(separator_cursor)},
m_min_digits{min_digits} {}
static std::unique_ptr<Highlighter> create(HighlighterParameters params, Highlighter*)
@ -1094,6 +1095,7 @@ struct LineNumbersHighlighter : Highlighter
static const ParameterDesc param_desc{
{ { "relative", { false, "" } },
{ "separator", { true, "" } },
{ "separator-cursor", { true, "" } },
{ "min-digits", { true, "" } },
{ "hlcursor", { false, "" } } },
ParameterDesc::Flags::None, 0, 0
@ -1101,16 +1103,21 @@ struct LineNumbersHighlighter : Highlighter
ParametersParser parser(params, param_desc);
StringView separator = parser.get_switch("separator").value_or("");
StringView separator_cursor = parser.get_switch("separator-cursor").value_or(separator);
if (separator.length() > 10)
throw runtime_error("separator length is limited to 10 bytes");
if (separator_cursor.column_length() != separator.column_length())
throw runtime_error("separator for active line should have the same length as 'separator'");
int min_digits = parser.get_switch("min-digits").map(str_to_int).value_or(2);
if (min_digits < 0)
throw runtime_error("min digits must be positive");
if (min_digits > 10)
throw runtime_error("min digits is limited to 10");
return std::make_unique<LineNumbersHighlighter>((bool)parser.get_switch("relative"), (bool)parser.get_switch("hlcursor"), separator.str(), min_digits);
return std::make_unique<LineNumbersHighlighter>((bool)parser.get_switch("relative"), (bool)parser.get_switch("hlcursor"), separator.str(), separator_cursor.str(), min_digits);
}
private:
@ -1141,8 +1148,12 @@ private:
snprintf(buffer, 16, format, std::abs(line_to_format));
const auto atom_face = last_line == current_line ? face_wrapped :
((m_hl_cursor_line and is_cursor_line) ? face_absolute : face);
const auto& separator = is_cursor_line && last_line != current_line
? m_separator_cursor : m_separator;
line.insert(line.begin(), {buffer, atom_face});
line.insert(line.begin() + 1, {m_separator, face});
line.insert(line.begin() + 1, {separator, face});
last_line = current_line;
}
@ -1174,6 +1185,7 @@ private:
const bool m_relative;
const bool m_hl_cursor_line;
const String m_separator;
const String m_separator_cursor;
const int m_min_digits;
};
@ -2272,7 +2284,7 @@ void register_highlighters()
"number-lines",
{ LineNumbersHighlighter::create,
"Display line numbers \n"
"Parameters: -relative, -hlcursor, -separator <separator text>, -min-digits <cols>\n" } });
"Parameters: -relative, -hlcursor, -separator <separator text>, -separator-cursor <separator text>, -min-digits <cols>\n" } });
registry.insert({
"show-matching",
{ create_matching_char_highlighter,