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

View file

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