1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 09:07:19 +03:00

avoid literal eol in status lines, replace them with another symbol

This commit is contained in:
Maxime Coste 2017-08-29 10:01:43 +07:00
parent 24234dffa3
commit 1709886873
7 changed files with 27 additions and 25 deletions

View File

@ -96,7 +96,7 @@ bool Client::process_pending_inputs()
catch (Kakoune::runtime_error& error)
{
write_to_debug_buffer(format("Error: {}", error.what()));
context().print_status({ error.what().str(), get_face("Error") });
context().print_status({ fix_atom_text(error.what().str()), get_face("Error") });
context().hooks().run_hook("RuntimeError", error.what(), context());
}
}

View File

@ -64,7 +64,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi
}
catch (Kakoune::runtime_error& error)
{
client->context().print_status({ error.what().str(), get_face("Error") });
client->context().print_status({ fix_atom_text(error.what().str()), get_face("Error") });
client->context().hooks().run_hook("RuntimeError", error.what(),
client->context());
}

View File

@ -1101,7 +1101,7 @@ const CommandDesc echo_cmd = {
CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
String message = join(parser, ' ', false);
String message = fix_atom_text(join(parser, ' ', false));
if (parser.get_switch("debug"))
write_to_debug_buffer(message);
else if (parser.get_switch("markup"))

View File

@ -303,4 +303,22 @@ DisplayLine parse_display_line(StringView line, const HashMap<String, DisplayLin
return res;
}
String fix_atom_text(StringView str)
{
String res;
auto pos = str.begin();
for (auto it = str.begin(), end = str.end(); it != end; ++it)
{
char c = *it;
if (c == '\n' or c == '\r')
{
res += StringView{pos, it};
res += c == '\n' ? "" : "";
pos = it+1;
}
}
res += StringView{pos, str.end()};
return res;
}
}

View File

@ -142,6 +142,7 @@ private:
AtomList m_atoms;
};
String fix_atom_text(StringView str);
DisplayLine parse_display_line(StringView line, const HashMap<String, DisplayLine>& builtins = {});
class DisplayBuffer : public UseMemoryDomain<MemoryDomain::Display>

View File

@ -500,23 +500,6 @@ public:
DisplayLine build_display_line(ColumnCount in_width)
{
auto cleanup = [](StringView str) {
String res;
auto pos = str.begin();
for (auto it = str.begin(), end = str.end(); it != end; ++it)
{
char c = *it;
if (c == '\n' or c == '\r')
{
res += StringView{pos, it};
res += c == '\n' ? "" : "";
pos = it+1;
}
}
res += StringView{pos, str.end()};
return res;
};
CharCount width = (int)in_width; // Todo: proper handling of char/column
kak_assert(m_cursor_pos <= m_line.char_length());
if (m_cursor_pos < m_display_pos)
@ -525,12 +508,12 @@ public:
m_display_pos = m_cursor_pos + 1 - width;
if (m_cursor_pos == m_line.char_length())
return DisplayLine{{ { cleanup(m_line.substr(m_display_pos, width-1)), get_face("StatusLine") },
return DisplayLine{{ { fix_atom_text(m_line.substr(m_display_pos, width-1)), get_face("StatusLine") },
{ " "_str, get_face("StatusCursor")} } };
else
return DisplayLine({ { cleanup(m_line.substr(m_display_pos, m_cursor_pos - m_display_pos)), get_face("StatusLine") },
{ cleanup(m_line.substr(m_cursor_pos,1)), get_face("StatusCursor") },
{ cleanup(m_line.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1)), get_face("StatusLine") } });
return DisplayLine({ { fix_atom_text(m_line.substr(m_display_pos, m_cursor_pos - m_display_pos)), get_face("StatusLine") },
{ fix_atom_text(m_line.substr(m_cursor_pos,1)), get_face("StatusCursor") },
{ fix_atom_text(m_line.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1)), get_face("StatusLine") } });
}
private:
CharCount m_cursor_pos = 0;

View File

@ -842,7 +842,7 @@ void use_selection_as_search_pattern(Context& context, NormalParams params)
const char reg = to_lower(params.reg ? params.reg : '/');
context.print_status({
format("register '{}' set to '{}'", reg, patterns[sels.main_index()]),
format("register '{}' set to '{}'", reg, fix_atom_text(patterns[sels.main_index()])),
get_face("Information") });
RegisterManager::instance()[reg].set(context, patterns);