diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index a498cc1c1..6f622cb5f 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1661,7 +1661,7 @@ class Coder: return True if not Path(full_path).exists(): - if not self.io.confirm_ask("Allow creation of new file?", subject=path): + if not self.io.confirm_ask("Create new file?", subject=path): self.io.tool_error(f"Skipping edits to {path}") return diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 9976cc220..35093f6d8 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -46,7 +46,7 @@ class EditBlockCoder(Coder): if edit[0] is None: edit = edit[1] # This is a shell command - if self.io.confirm_ask("Run this shell command?", subject=edit.strip()): + if self.io.confirm_ask("Run shell command?", subject=edit.strip()): self.io.tool_output() try: # Add the command to input history diff --git a/aider/io.py b/aider/io.py index 52bf2acfe..e26472eb5 100644 --- a/aider/io.py +++ b/aider/io.py @@ -356,16 +356,48 @@ class InputOutput: def confirm_ask(self, question, default="y", subject=None): self.num_user_asks += 1 + if default == "y": + question += " [Y/n] " + elif default == "n": + question += " [y/N] " + else: + question += " [y/n] " + if subject: self.tool_output() self.tool_output(subject, bold=True) + if self.pretty and self.user_input_color: + style = {"": self.user_input_color} + else: + style = dict() + + from prompt_toolkit.completion import WordCompleter + + completer = WordCompleter(["yes", "no"]) + + from prompt_toolkit import prompt + from prompt_toolkit.validation import Validator + + def is_yesno(text): + return "yes".startswith(text.lower()) or "no".startswith(text.lower()) + + validator = Validator.from_callable( + is_yesno, + error_message="Answer yes or no.", + move_cursor_to_end=True, + ) + if self.yes is True: res = "y" elif self.yes is False: res = "n" else: - res = prompt(question + " ", default=default) + res = prompt( + question, style=Style.from_dict(style), completer=completer, validator=validator + ) + if not res and default: + res = default res = res.lower().strip() is_yes = res in ("y", "yes")