From 79769749007a08a987562ee109cee1e521f07c48 Mon Sep 17 00:00:00 2001 From: Erhhung Yuan Date: Fri, 13 Sep 2024 15:06:44 -0700 Subject: [PATCH] Fixed #925: Exiting by Ctrl-D throws EOFError --- .../terminal_interface/terminal_interface.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/interpreter/terminal_interface/terminal_interface.py b/interpreter/terminal_interface/terminal_interface.py index bf019eb03b..d0cb367924 100644 --- a/interpreter/terminal_interface/terminal_interface.py +++ b/interpreter/terminal_interface/terminal_interface.py @@ -92,11 +92,16 @@ def terminal_interface(interpreter, message): interpreter.messages = interpreter.messages[:-1] else: ### This is the primary input for Open Interpreter. - message = ( - cli_input("> ").strip() - if interpreter.multi_line - else input("> ").strip() - ) + try: + message = ( + cli_input("> ").strip() + if interpreter.multi_line + else input("> ").strip() + ) + except (KeyboardInterrupt, EOFError): + # Treat Ctrl-D on an empty line the same as Ctrl-C by exiting gracefully + interpreter.display_message("\n\n`Exiting...`") + raise KeyboardInterrupt try: # This lets users hit the up arrow key for past messages