This commit is contained in:
Paul Gauthier 2023-05-12 10:53:23 -07:00
parent 0325fc40ac
commit b7299565f1
2 changed files with 76 additions and 77 deletions

View file

@ -33,7 +33,8 @@ class Coder:
def __init__(self, main_model, fnames, pretty, history_file, show_diffs, auto_commits, yes):
self.abs_fnames = set()
self.yes = yes
self.input = getinput.Input(yes)
self.history_file = history_file
self.auto_commits = auto_commits
@ -117,7 +118,7 @@ class Coder:
self.console.print(f"Files not tracked in {repo.git_dir}:")
for fn in new_files:
self.console.print(f" {fn}")
if getinput.confirm_ask("Add them?", default="y"):
if self.input.confirm_ask("Add them?"):
for relative_fname in new_files:
repo.git.add(relative_fname)
self.console.print(f"Added {relative_fname} to the git repo")
@ -203,7 +204,7 @@ class Coder:
else:
print()
inp = getinput.get_input(self.history_file, self.abs_fnames, self.commands)
inp = self.input.get_input(self.history_file, self.abs_fnames, self.commands)
self.num_control_c = 0
@ -321,7 +322,7 @@ class Coder:
for rel_fname in mentioned_rel_fnames:
self.console.print(f"{rel_fname}")
if not getinput.confirm_ask("Add {path} to git?", default="y"):
if not self.input.confirm_ask("Add {path} to git?"):
return
for rel_fname in mentioned_rel_fnames:
@ -403,7 +404,7 @@ class Coder:
question = (
f"Allow edits to {path} which was not previously provided?" # noqa: E501
)
if not getinput.confirm_ask(question, default="y"):
if not self.input.confirm_ask(question):
self.console.print(f"[red]Skipping edit to {path}")
continue
@ -411,10 +412,7 @@ class Coder:
Path(full_path).touch()
self.abs_fnames.add(full_path)
if self.repo and getinput.confirm_ask(
f"Add {path} to git?",
default="y",
):
if self.repo and self.input.confirm_ask(f"Add {path} to git?"):
self.repo.git.add(full_path)
edited.add(path)
@ -517,7 +515,7 @@ class Coder:
self.console.print("Files have uncommitted changes.\n")
self.console.print(f"Suggested commit message:\n{commit_message}\n")
res = getinput.prompt_ask(
res = self.input.prompt_ask(
"Commit before the chat proceeds [y/n/commit message]?",
default=commit_message,
).strip()

View file

@ -50,7 +50,11 @@ class FileContentCompleter(Completer):
yield Completion(word, start_position=-len(last_word))
def canned_input(show_prompt):
class Input:
def __init__(self, yes):
self.yes = yes
def canned_input(self, show_prompt):
console = Console()
input_line = input()
@ -63,8 +67,7 @@ def canned_input(show_prompt):
console.print()
return input_line
def get_input(history_file, fnames, commands):
def get_input(self, history_file, fnames, commands):
fnames = list(fnames)
if len(fnames) > 1:
common_prefix = os.path.commonpath(fnames)
@ -82,7 +85,7 @@ def get_input(history_file, fnames, commands):
show += "> "
if not sys.stdin.isatty():
return canned_input(show)
return self.canned_input(show)
inp = ""
multiline_input = False
@ -116,14 +119,12 @@ def get_input(history_file, fnames, commands):
print()
return inp
def confirm_ask(question, default=None, yes=False):
if yes:
def confirm_ask(self, question, default="y"):
if self.yes:
return True
return prompt(question + " ", default=default)
def prompt_ask(question, default=None, yes=False):
if yes:
def prompt_ask(self, question, default=None):
if self.yes:
return True
return prompt(question + " ", default=default)