From 36e3e7b75a284493ea2442f8f9ec8d5fa302b9ce Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Sun, 18 Aug 2019 11:57:10 +1000 Subject: [PATCH] Shell: Support forward delete --- Shell/LineEditor.cpp | 23 +++++++++++++++++++++++ Shell/LineEditor.h | 1 + 2 files changed, 24 insertions(+) diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp index 6b1086ff9dd..5c1e6a45dad 100644 --- a/Shell/LineEditor.cpp +++ b/Shell/LineEditor.cpp @@ -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; diff --git a/Shell/LineEditor.h b/Shell/LineEditor.h index f7fd0c3e262..50a696b83c8 100644 --- a/Shell/LineEditor.h +++ b/Shell/LineEditor.h @@ -32,6 +32,7 @@ private: Free, ExpectBracket, ExpectFinal, + ExpectTerminator, }; InputState m_state { InputState::Free }; };