1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 02:28: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

@ -80,9 +80,13 @@ public:
explicit Editor(bool always_refresh = false);
~Editor();
String get_line(const String& prompt);
void initialize()
{
ASSERT(!m_initialized);
if (m_initialized)
return;
struct termios termios;
tcgetattr(0, &termios);
m_default_termios = termios; // grab a copy to restore
@ -94,8 +98,6 @@ public:
m_initialized = true;
}
String get_line(const String& prompt);
void add_to_history(const String&);
const Vector<String>& history() const { return m_history; }
@ -194,6 +196,13 @@ private:
void refresh_display();
void cleanup();
void restore()
{
ASSERT(m_initialized);
tcsetattr(0, TCSANOW, &m_default_termios);
m_initialized = false;
}
size_t current_prompt_length() const
{
return m_cached_prompt_valid ? m_cached_prompt_length : m_old_prompt_length;