1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:58:12 +00:00

LibLine: Handle initialize() internally

This patch makes initialize() transparent to the users, but exposes it
publicly, as the users might need a copy of the default termios (i.e.
Shell)
This commit is contained in:
AnotherTest 2020-04-29 01:46:19 +04:30 committed by Andreas Kling
parent 7ecf29f206
commit 9473733d7a
4 changed files with 15 additions and 8 deletions

View file

@ -50,7 +50,7 @@ Editor::Editor(bool always_refresh)
Editor::~Editor()
{
if (m_initialized)
tcsetattr(0, TCSANOW, &m_default_termios);
restore();
}
void Editor::add_to_history(const String& line)
@ -124,6 +124,7 @@ void Editor::stylize(const Span& span, const Style& style)
String Editor::get_line(const String& prompt)
{
initialize();
m_is_editing = true;
set_prompt(prompt);
@ -142,6 +143,7 @@ String Editor::get_line(const String& prompt)
auto string = String::copy(m_buffer);
m_buffer.clear();
m_is_editing = false;
restore();
return string;
}
char keybuf[16];
@ -648,7 +650,6 @@ String Editor::get_line(const String& prompt)
m_pre_search_buffer.append(ch);
m_pre_search_cursor = m_cursor;
m_search_editor = make<Editor>(true); // Has anyone seen 'Inception'?
m_search_editor->initialize();
m_search_editor->on_display_refresh = [this](Editor& search_editor) {
search(StringView { search_editor.buffer().data(), search_editor.buffer().size() });
refresh_display();