1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 14:17:42 +00:00

Shell: Support forward delete

This commit is contained in:
Conrad Pankoff 2019-08-18 11:57:10 +10:00 committed by Andreas Kling
parent 266b9cb654
commit 36e3e7b75a
2 changed files with 24 additions and 0 deletions

View file

@ -72,6 +72,22 @@ String LineEditor::get_line(const String& prompt)
exit(2); 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) { for (ssize_t i = 0; i < nread; ++i) {
char ch = keybuf[i]; char ch = keybuf[i];
if (ch == 0) if (ch == 0)
@ -136,12 +152,19 @@ String LineEditor::get_line(const String& prompt)
} }
m_state = InputState::Free; m_state = InputState::Free;
continue; continue;
case '3':
do_delete();
m_state = InputState::ExpectTerminator;
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;
continue; continue;
} }
break; break;
case InputState::ExpectTerminator:
m_state = InputState::Free;
continue;
case InputState::Free: case InputState::Free:
if (ch == 27) { if (ch == 27) {
m_state = InputState::ExpectBracket; m_state = InputState::ExpectBracket;

View file

@ -32,6 +32,7 @@ private:
Free, Free,
ExpectBracket, ExpectBracket,
ExpectFinal, ExpectFinal,
ExpectTerminator,
}; };
InputState m_state { InputState::Free }; InputState m_state { InputState::Free };
}; };