mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
Modify get_input() to accumulate input lines between { and } and return the concatenated lines with '\n'.
# Context: USER: modify get_input(). if the user inputs a line with just { then keep accumulating input lines until you receive a line with just }. in this case, discard the {} lines and return the rest of the lines concatenated with '\n' ASSISTANT: To modify the `get_input()` function to accumulate input lines between `{` and `}`, we will change the function to handle this case. Here's the updated code for the `get_input()` function: ```python coder.py <<<<<<< ORIGINAL def get_input(self): if self.pretty: self.console.rule() else: print() inp = "" if self.pretty: print(Fore.GREEN, end="\r") else: print() while not inp.strip(): try: inp = input("> ") except EOFError: return ### if self.pretty: print(Style.RESET_ALL) else: print() readline.write_history_file(history_file) return inp ======= def get_input(self): if self.pretty: self.console.rule() else: print() inp = "" multiline_input = False if self.pretty: print(Fore.GREEN, end="\r") else: print() while True: try: line = input("> ") 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 if self.pretty: print(Style.RESET_ALL) else: print() readline.write_history_file(history_file) return inp >>>>>>> UPDATED ``` This change will allow the `get_input()` function to accumulate input lines between `{` and `}` and return the concatenated lines with '\n'.
This commit is contained in:
parent
551cc011aa
commit
42598e2329
1 changed files with 15 additions and 5 deletions
18
coder.py
18
coder.py
|
@ -141,18 +141,29 @@ class Coder:
|
||||||
print()
|
print()
|
||||||
|
|
||||||
inp = ""
|
inp = ""
|
||||||
|
multiline_input = False
|
||||||
if self.pretty:
|
if self.pretty:
|
||||||
print(Fore.GREEN, end="\r")
|
print(Fore.GREEN, end="\r")
|
||||||
else:
|
else:
|
||||||
print()
|
print()
|
||||||
|
|
||||||
while not inp.strip():
|
while True:
|
||||||
try:
|
try:
|
||||||
inp = input("> ")
|
line = input("> ")
|
||||||
except EOFError:
|
except EOFError:
|
||||||
return
|
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
|
||||||
|
|
||||||
if self.pretty:
|
if self.pretty:
|
||||||
print(Style.RESET_ALL)
|
print(Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
|
@ -160,7 +171,6 @@ class Coder:
|
||||||
|
|
||||||
readline.write_history_file(history_file)
|
readline.write_history_file(history_file)
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
def check_for_local_edits(self, init=False):
|
def check_for_local_edits(self, init=False):
|
||||||
last_modified = max(Path(fname).stat().st_mtime for fname in self.fnames)
|
last_modified = max(Path(fname).stat().st_mtime for fname in self.fnames)
|
||||||
since = last_modified - self.last_modified
|
since = last_modified - self.last_modified
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue