From 8c05e78b6cb0d53cd9e08e3133dfa223fcd3e2dc Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sat, 30 May 2020 22:35:40 +0430 Subject: [PATCH] Shell: Treat ^D as builtin_exit when not in a continuation --- Shell/Shell.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index e0098c8fe1..f1bcf65620 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -1719,11 +1719,24 @@ bool Shell::read_single_line() auto line_result = editor->get_line(prompt()); if (line_result.is_error()) { - m_complete_line_builder.clear(); - m_should_continue = ContinuationRequest::Nothing; - m_should_break_current_command = false; - Core::EventLoop::current().quit(line_result.error() == Line::Editor::Error::Eof ? 0 : 1); - return false; + if (line_result.error() == Line::Editor::Error::Eof || line_result.error() == Line::Editor::Error::Empty) { + // Pretend the user tried to execute builtin_exit() + // but only if there's no continuation. + if (m_should_continue == ContinuationRequest::Nothing) { + m_complete_line_builder.clear(); + run_command("exit"); + return read_single_line(); + } else { + // Ignore the Eof. + return true; + } + } else { + m_complete_line_builder.clear(); + m_should_continue = ContinuationRequest::Nothing; + m_should_break_current_command = false; + Core::EventLoop::current().quit(1); + return false; + } } auto& line = line_result.value();