1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibLineEdit + Shell: Handle Termios internally and give a copy if asked

This moves the Termios logic inside LibLineEdit and allows users to
simply forget about the existence of termios if they so choose to :^)
This commit is contained in:
AnotherTest 2020-03-30 22:42:50 +04:30 committed by Andreas Kling
parent 5062a7d4cd
commit 6f407fff32
3 changed files with 19 additions and 19 deletions

View file

@ -30,9 +30,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
LineEditor::LineEditor(struct termios termios)
: m_termios(termios)
, m_initialized(true)
LineEditor::LineEditor()
{
struct winsize ws;
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
@ -41,13 +39,9 @@ LineEditor::LineEditor(struct termios termios)
m_num_columns = ws.ws_col;
}
LineEditor::LineEditor()
: LineEditor(termios {})
{
}
LineEditor::~LineEditor()
{
tcsetattr(0, TCSANOW, &m_default_termios);
}
void LineEditor::add_to_history(const String& line)
@ -378,7 +372,7 @@ String LineEditor::get_line(const String& prompt)
do_backspace();
continue;
}
if (ch == 0xc) { // ^L
if (ch == 0xc) { // ^L
printf("\033[3J\033[H\033[2J"); // Clear screen.
fputs(prompt.characters(), stdout);
for (size_t i = 0; i < m_buffer.size(); ++i)