From 845094f9e45b7f785a98b56cfd3416a9fa8d9ce8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 1 Nov 2019 21:43:05 +0100 Subject: [PATCH] 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 "" and exit the shell without error. Fixes #701. --- Shell/LineEditor.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Shell/LineEditor.cpp b/Shell/LineEditor.cpp index ebfaf10150..053c6230d9 100644 --- a/Shell/LineEditor.cpp +++ b/Shell/LineEditor.cpp @@ -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("\n"); + exit(0); + } + continue; + } if (ch == 0x05) { // ^E if (m_cursor < m_buffer.size()) { printf("\033[%dC", m_buffer.size() - m_cursor);