refactor: Handle EOFError gracefully in confirm_ask and prompt_ask methods

This commit is contained in:
Paul Gauthier (aider) 2025-03-05 15:30:44 -08:00
parent d7efbad3df
commit ff3d2b006f

View file

@ -750,6 +750,7 @@ class InputOutput:
self.user_input(f"{question}{res}", log_only=False)
else:
while True:
try:
if self.prompt_session:
res = self.prompt_session.prompt(
question,
@ -758,6 +759,10 @@ class InputOutput:
)
else:
res = input(question)
except EOFError:
# Treat EOF (Ctrl+D) as if the user pressed Enter
res = default
break
if not res:
res = default
@ -812,6 +817,7 @@ class InputOutput:
elif self.yes is False:
res = "no"
else:
try:
if self.prompt_session:
res = self.prompt_session.prompt(
question + " ",
@ -821,6 +827,9 @@ class InputOutput:
)
else:
res = input(question + " ")
except EOFError:
# Treat EOF (Ctrl+D) as if the user pressed Enter
res = default
hist = f"{question.strip()} {res.strip()}"
self.append_chat_history(hist, linebreak=True, blockquote=True)