mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Shell: Implement support for terminal clearing with ^L.
Make LineEditor::get_line() responsible for printing the prompt. That way we can re-prompt after clearing the screen on ^L. This makes the Serenity Terminal feel a little bit more like home :^)
This commit is contained in:
parent
2d4d465206
commit
253e391bfc
3 changed files with 23 additions and 11 deletions
|
@ -37,8 +37,11 @@ void LineEditor::append(const String& string)
|
|||
m_cursor = m_buffer.size();
|
||||
}
|
||||
|
||||
String LineEditor::get_line()
|
||||
String LineEditor::get_line(const String& prompt)
|
||||
{
|
||||
fputs(prompt.characters(), stdout);
|
||||
fflush(stdout);
|
||||
|
||||
m_history_cursor = m_history.size();
|
||||
m_cursor = 0;
|
||||
for (;;) {
|
||||
|
@ -190,6 +193,16 @@ String LineEditor::get_line()
|
|||
do_backspace();
|
||||
continue;
|
||||
}
|
||||
if (ch == 0xc) { // ^L
|
||||
printf("\033[3J\033[H\033[2J"); // Clear screen.
|
||||
fputs(prompt.characters(), stdout);
|
||||
for (int i = 0; i < m_buffer.size(); ++i)
|
||||
fputc(m_buffer[i], stdout);
|
||||
if (m_cursor < m_buffer.size())
|
||||
printf("\033[%dD", m_buffer.size() - m_cursor); // Move cursor N steps left.
|
||||
fflush(stdout);
|
||||
continue;
|
||||
}
|
||||
putchar(ch);
|
||||
fflush(stdout);
|
||||
if (ch == '\n') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue