Shell: Exit the shell on (interactive) EOF with empty buffer

In other words, if the user presses EOF (normally Ctrl+D), we now print
out "<EOF>" and exit the shell without error.

Fixes #701.
This commit is contained in:
Andreas Kling 2019-11-01 21:43:05 +01:00
parent 390b219cd1
commit 845094f9e4
Notes: sideshowbarker 2024-07-19 11:28:53 +09:00

View file

@ -302,6 +302,13 @@ String LineEditor::get_line(const String& prompt)
} }
continue; continue;
} }
if (ch == g.termios.c_cc[VEOF]) { // Normally ^D
if (m_buffer.is_empty()) {
printf("<EOF>\n");
exit(0);
}
continue;
}
if (ch == 0x05) { // ^E if (ch == 0x05) { // ^E
if (m_cursor < m_buffer.size()) { if (m_cursor < m_buffer.size()) {
printf("\033[%dC", m_buffer.size() - m_cursor); printf("\033[%dC", m_buffer.size() - m_cursor);