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

View file

@ -302,6 +302,13 @@ String LineEditor::get_line(const String& prompt)
}
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 (m_cursor < m_buffer.size()) {
printf("\033[%dC", m_buffer.size() - m_cursor);