mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
Move get_input
function into utils.py
and update the call to get_input
in coder.py
to use the new utils.get_input
function.
# Context: USER: move get_input into utils. pass in history_file and fnames as params rather than referencing them with self. ASSISTANT: To move the `get_input` function into `utils.py`, we will remove it from the `Coder` class in `coder.py` and add it to `utils.py`. We will also update the function to accept `history_file` and `fnames` as parameters. ```python coder.py <<<<<<< ORIGINAL def get_input(self): inp = "" multiline_input = False style = Style.from_dict({'': 'green'}) while True: completer_instance = FileContentCompleter(self.fnames) if multiline_input: show = ". " else: show = "> " try: line = prompt( show, completer=completer_instance, history=FileHistory(self.history_file), style=style, ) except EOFError: return if line.strip() == "{" and not multiline_input: multiline_input = True continue elif line.strip() == "}" and multiline_input: break elif multiline_input: inp += line + "\n" else: inp = line break print() return inp ======= >>>>>>> UPDATED ``` ```python utils.py <<<<<<< ORIGINAL ======= def get_input(history_file, fnames): inp = "" multiline_input = False style = Style.from_dict({'': 'green'}) while True: completer_instance = FileContentCompleter(fnames) if multiline_input: show = ". " else: show = "> " try: line = prompt( show, completer=completer_instance, history=FileHistory(history_file), style=style, ) except EOFError: return if line.strip() == "{" and not multiline_input: multiline_input = True continue elif line.strip() == "}" and multiline_input: break elif multiline_input: inp += line + "\n" else: inp = line break print() return inp >>>>>>> UPDATED ``` Now, update the call to `get_input` in `coder.py` to use the new `utils.get_input` function: ```python coder.py <<<<<<< ORIGINAL inp = self.get_input() ======= inp = utils.get_input(self.history_file, self.fnames) >>>>>>> UPDATED ```
This commit is contained in:
parent
64c3af37df
commit
6419e6c390
2 changed files with 36 additions and 37 deletions
38
coder.py
38
coder.py
|
@ -141,42 +141,6 @@ class Coder:
|
|||
prompt += utils.quoted_file(fname)
|
||||
return prompt
|
||||
|
||||
def get_input(self):
|
||||
inp = ""
|
||||
multiline_input = False
|
||||
|
||||
style = Style.from_dict({'': 'green'})
|
||||
|
||||
while True:
|
||||
completer_instance = FileContentCompleter(self.fnames)
|
||||
if multiline_input:
|
||||
show = ". "
|
||||
else:
|
||||
show = "> "
|
||||
|
||||
try:
|
||||
line = prompt(
|
||||
show,
|
||||
completer=completer_instance,
|
||||
history=FileHistory(self.history_file),
|
||||
style=style,
|
||||
)
|
||||
except EOFError:
|
||||
return
|
||||
if line.strip() == "{" and not multiline_input:
|
||||
multiline_input = True
|
||||
continue
|
||||
elif line.strip() == "}" and multiline_input:
|
||||
break
|
||||
elif multiline_input:
|
||||
inp += line + "\n"
|
||||
else:
|
||||
inp = line
|
||||
break
|
||||
|
||||
print()
|
||||
return inp
|
||||
|
||||
def get_last_modified(self):
|
||||
return max(Path(fname).stat().st_mtime for fname in self.fnames)
|
||||
|
||||
|
@ -216,7 +180,7 @@ class Coder:
|
|||
else:
|
||||
print()
|
||||
|
||||
inp = self.get_input()
|
||||
inp = utils.get_input(self.history_file, self.fnames)
|
||||
if inp is None:
|
||||
return
|
||||
|
||||
|
|
35
utils.py
35
utils.py
|
@ -107,3 +107,38 @@ def do_replace(fname, before_text, after_text):
|
|||
|
||||
fname.write_text(new_content)
|
||||
return True
|
||||
def get_input(history_file, fnames):
|
||||
inp = ""
|
||||
multiline_input = False
|
||||
|
||||
style = Style.from_dict({'': 'green'})
|
||||
|
||||
while True:
|
||||
completer_instance = FileContentCompleter(fnames)
|
||||
if multiline_input:
|
||||
show = ". "
|
||||
else:
|
||||
show = "> "
|
||||
|
||||
try:
|
||||
line = prompt(
|
||||
show,
|
||||
completer=completer_instance,
|
||||
history=FileHistory(history_file),
|
||||
style=style,
|
||||
)
|
||||
except EOFError:
|
||||
return
|
||||
if line.strip() == "{" and not multiline_input:
|
||||
multiline_input = True
|
||||
continue
|
||||
elif line.strip() == "}" and multiline_input:
|
||||
break
|
||||
elif multiline_input:
|
||||
inp += line + "\n"
|
||||
else:
|
||||
inp = line
|
||||
break
|
||||
|
||||
print()
|
||||
return inp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue