mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 03:47:34 +00:00
Shell: Support home/end keys for line editing.
This commit is contained in:
parent
d53941a466
commit
b04f08ba48
2 changed files with 24 additions and 1 deletions
|
@ -769,6 +769,12 @@ void Terminal::keydown_event(GKeyEvent& event)
|
||||||
case KeyCode::Key_Left:
|
case KeyCode::Key_Left:
|
||||||
write(m_ptm_fd, "\033[D", 3);
|
write(m_ptm_fd, "\033[D", 3);
|
||||||
break;
|
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:
|
default:
|
||||||
write(m_ptm_fd, &ch, 1);
|
write(m_ptm_fd, &ch, 1);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -21,8 +21,9 @@ void LineEditor::add_to_history(const String& line)
|
||||||
|
|
||||||
void LineEditor::clear_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);
|
fputc(0x8, stdout);
|
||||||
|
fputs("\033[K", stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
m_buffer.clear();
|
m_buffer.clear();
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
|
@ -110,6 +111,22 @@ String LineEditor::get_line()
|
||||||
}
|
}
|
||||||
m_state = InputState::Free;
|
m_state = InputState::Free;
|
||||||
continue;
|
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:
|
default:
|
||||||
dbgprintf("Shell: Unhandled final: %b (%c)\n", ch, ch);
|
dbgprintf("Shell: Unhandled final: %b (%c)\n", ch, ch);
|
||||||
m_state = InputState::Free;
|
m_state = InputState::Free;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue