mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Shell: Support forward delete
This commit is contained in:
parent
266b9cb654
commit
36e3e7b75a
Notes:
sideshowbarker
2024-07-19 12:38:08 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/36e3e7b75a2 Pull-request: https://github.com/SerenityOS/serenity/pull/461
2 changed files with 24 additions and 0 deletions
|
@ -72,6 +72,22 @@ String LineEditor::get_line(const String& prompt)
|
|||
exit(2);
|
||||
}
|
||||
|
||||
auto do_delete = [&] {
|
||||
if (m_cursor == m_buffer.size()) {
|
||||
fputc('\a', stdout);
|
||||
fflush(stdout);
|
||||
return;
|
||||
}
|
||||
m_buffer.remove(m_cursor - 1);
|
||||
fputs("\033[3~", stdout);
|
||||
fflush(stdout);
|
||||
vt_save_cursor();
|
||||
vt_clear_to_end_of_line();
|
||||
for (int i = m_cursor; i < m_buffer.size(); ++i)
|
||||
fputc(m_buffer[i], stdout);
|
||||
vt_restore_cursor();
|
||||
};
|
||||
|
||||
for (ssize_t i = 0; i < nread; ++i) {
|
||||
char ch = keybuf[i];
|
||||
if (ch == 0)
|
||||
|
@ -136,12 +152,19 @@ String LineEditor::get_line(const String& prompt)
|
|||
}
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
case '3':
|
||||
do_delete();
|
||||
m_state = InputState::ExpectTerminator;
|
||||
continue;
|
||||
default:
|
||||
dbgprintf("Shell: Unhandled final: %b (%c)\n", ch, ch);
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case InputState::ExpectTerminator:
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
case InputState::Free:
|
||||
if (ch == 27) {
|
||||
m_state = InputState::ExpectBracket;
|
||||
|
|
|
@ -32,6 +32,7 @@ private:
|
|||
Free,
|
||||
ExpectBracket,
|
||||
ExpectFinal,
|
||||
ExpectTerminator,
|
||||
};
|
||||
InputState m_state { InputState::Free };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue