Move control character escaping responsibility to the terminal UI
Fix atom text at display time, allow tabs/eol/etc... in display atoms and escape them just-in-time Fixes #4293
This commit is contained in:
parent
94388dc51e
commit
7187784936
|
@ -107,8 +107,7 @@ bool Client::process_pending_inputs()
|
|||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
write_to_debug_buffer(format("Error: {}", error.what()));
|
||||
context().print_status({ fix_atom_text(error.what().str()),
|
||||
context().faces()["Error"] });
|
||||
context().print_status({error.what().str(), context().faces()["Error"] });
|
||||
context().hooks().run_hook(Hook::RuntimeError, error.what(), context());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi
|
|||
}
|
||||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
client->context().print_status({ fix_atom_text(error.what().str()),
|
||||
client->context().faces()["Error"] });
|
||||
client->context().print_status({error.what().str(), client->context().faces()["Error"]});
|
||||
client->context().hooks().run_hook(Hook::RuntimeError, error.what(),
|
||||
client->context());
|
||||
}
|
||||
|
|
|
@ -1359,13 +1359,12 @@ const CommandDesc echo_cmd = {
|
|||
if (auto filename = parser.get_switch("to-file"))
|
||||
return write_to_file(*filename, message);
|
||||
|
||||
message = fix_atom_text(message);
|
||||
if (parser.get_switch("debug"))
|
||||
write_to_debug_buffer(message);
|
||||
else if (parser.get_switch("markup"))
|
||||
context.print_status(parse_display_line(message, context.faces()));
|
||||
else
|
||||
context.print_status({replace(message, '\t', ' '), context.faces()["StatusLine"]});
|
||||
context.print_status({message, context.faces()["StatusLine"]});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2161,7 +2160,7 @@ const CommandDesc prompt_cmd = {
|
|||
}
|
||||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
context.print_status({fix_atom_text(error.what()), context.faces()["Error"]});
|
||||
context.print_status({error.what().str(), context.faces()["Error"]});
|
||||
context.hooks().run_hook(Hook::RuntimeError, error.what(), context);
|
||||
}
|
||||
});
|
||||
|
@ -2542,7 +2541,7 @@ const CommandDesc fail_cmd = {
|
|||
CommandCompleter{},
|
||||
[](const ParametersParser& parser, Context&, const ShellContext&)
|
||||
{
|
||||
throw failure{fix_atom_text(join(parser, " "))};
|
||||
throw failure{join(parser, " ")};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -332,22 +332,4 @@ DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const
|
|||
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 >= 0 and c <= 0x1F)
|
||||
{
|
||||
res += StringView{pos, it};
|
||||
res += String{Codepoint{(uint32_t)(0x2400 + c)}};
|
||||
pos = it+1;
|
||||
}
|
||||
}
|
||||
res += StringView{pos, str.end()};
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -156,7 +156,6 @@ private:
|
|||
using DisplayLineList = Vector<DisplayLine>;
|
||||
class FaceRegistry;
|
||||
|
||||
String fix_atom_text(StringView str);
|
||||
DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins = {});
|
||||
|
||||
class DisplayBuffer : public UseMemoryDomain<MemoryDomain::Display>
|
||||
|
|
|
@ -575,12 +575,12 @@ public:
|
|||
const Face cursor_face = m_faces["StatusCursor"];
|
||||
|
||||
if (m_cursor_pos == str.char_length())
|
||||
return DisplayLine{{ { fix_atom_text(str.substr(m_display_pos, width-1)), line_face },
|
||||
return DisplayLine{{ { str.substr(m_display_pos, width-1).str(), line_face },
|
||||
{ " "_str, cursor_face} } };
|
||||
else
|
||||
return DisplayLine({ { fix_atom_text(str.substr(m_display_pos, m_cursor_pos - m_display_pos)), line_face },
|
||||
{ fix_atom_text(str.substr(m_cursor_pos,1)), cursor_face },
|
||||
{ fix_atom_text(str.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1)), line_face } });
|
||||
return DisplayLine({ { str.substr(m_display_pos, m_cursor_pos - m_display_pos).str(), line_face },
|
||||
{ str.substr(m_cursor_pos,1).str(), cursor_face },
|
||||
{ str.substr(m_cursor_pos+1, width - m_cursor_pos + m_display_pos - 1).str(), line_face } });
|
||||
}
|
||||
private:
|
||||
CharCount m_cursor_pos = 0;
|
||||
|
|
|
@ -966,7 +966,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, fix_atom_text(pattern)),
|
||||
format("register '{}' set to '{}'", reg, pattern),
|
||||
context.faces()["Information"] });
|
||||
|
||||
RegisterManager::instance()[reg].set(context, {pattern});
|
||||
|
|
|
@ -23,6 +23,24 @@ namespace Kakoune
|
|||
using std::min;
|
||||
using std::max;
|
||||
|
||||
static 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 >= 0 and c <= 0x1F)
|
||||
{
|
||||
res += StringView{pos, it};
|
||||
res += String{Codepoint{(uint32_t)(0x2400 + c)}};
|
||||
pos = it+1;
|
||||
}
|
||||
}
|
||||
res += StringView{pos, str.end()};
|
||||
return res;
|
||||
}
|
||||
|
||||
struct TerminalUI::Window::Line
|
||||
{
|
||||
struct Atom
|
||||
|
@ -58,11 +76,11 @@ struct TerminalUI::Window::Line
|
|||
{
|
||||
if (not atoms.empty() and atoms.back().face == face and (atoms.back().skip == 0 or text.empty()))
|
||||
{
|
||||
atoms.back().text += text;
|
||||
atoms.back().text += fix_atom_text(text);
|
||||
atoms.back().skip += skip;
|
||||
}
|
||||
else
|
||||
atoms.push_back({text.str(), skip, face});
|
||||
atoms.push_back({fix_atom_text(text), skip, face});
|
||||
}
|
||||
|
||||
void resize(ColumnCount width)
|
||||
|
|
Loading…
Reference in New Issue
Block a user