Shell: Support home/end keys for line editing.
This commit is contained in:
parent
d53941a466
commit
b04f08ba48
Notes:
sideshowbarker
2024-07-19 14:12:46 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b04f08ba483
2 changed files with 24 additions and 1 deletions
|
@ -769,6 +769,12 @@ void Terminal::keydown_event(GKeyEvent& event)
|
|||
case KeyCode::Key_Left:
|
||||
write(m_ptm_fd, "\033[D", 3);
|
||||
break;
|
||||
case KeyCode::Key_Home:
|
||||
write(m_ptm_fd, "\033[H", 3);
|
||||
break;
|
||||
case KeyCode::Key_End:
|
||||
write(m_ptm_fd, "\033[F", 3);
|
||||
break;
|
||||
default:
|
||||
write(m_ptm_fd, &ch, 1);
|
||||
break;
|
||||
|
|
|
@ -21,8 +21,9 @@ void LineEditor::add_to_history(const String& line)
|
|||
|
||||
void LineEditor::clear_line()
|
||||
{
|
||||
for (int i = 0; i < m_buffer.size(); ++i)
|
||||
for (int i = 0; i < m_cursor; ++i)
|
||||
fputc(0x8, stdout);
|
||||
fputs("\033[K", stdout);
|
||||
fflush(stdout);
|
||||
m_buffer.clear();
|
||||
m_cursor = 0;
|
||||
|
@ -110,6 +111,22 @@ String LineEditor::get_line()
|
|||
}
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
case 'H':
|
||||
if (m_cursor > 0) {
|
||||
fprintf(stdout, "\033[%dD", m_cursor);
|
||||
fflush(stdout);
|
||||
m_cursor = 0;
|
||||
}
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
case 'F':
|
||||
if (m_cursor < m_buffer.size()) {
|
||||
fprintf(stdout, "\033[%dC", m_buffer.size() - m_cursor);
|
||||
fflush(stdout);
|
||||
m_cursor = m_buffer.size();
|
||||
}
|
||||
m_state = InputState::Free;
|
||||
continue;
|
||||
default:
|
||||
dbgprintf("Shell: Unhandled final: %b (%c)\n", ch, ch);
|
||||
m_state = InputState::Free;
|
||||
|
|
Loading…
Add table
Reference in a new issue