diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 12752d43b04..3e628deb8d1 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -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; diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp index df44c54a6d0..b843709eef3 100644 --- a/Shell/LineEditor.cpp +++ b/Shell/LineEditor.cpp @@ -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;