mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
better live output of multi file edits
This commit is contained in:
parent
f187cf0346
commit
f9086e66d3
3 changed files with 27 additions and 14 deletions
|
@ -527,19 +527,23 @@ class Coder:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.pretty:
|
if self.pretty:
|
||||||
show_resp = self.modify_incremental_response()
|
self.live_incremental_response(live, False)
|
||||||
if show_resp:
|
|
||||||
md = Markdown(
|
|
||||||
show_resp, style=self.assistant_output_color, code_theme="default"
|
|
||||||
)
|
|
||||||
live.update(md)
|
|
||||||
else:
|
else:
|
||||||
sys.stdout.write(text)
|
sys.stdout.write(text)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
finally:
|
finally:
|
||||||
|
self.live_incremental_response(live, True)
|
||||||
if live:
|
if live:
|
||||||
live.stop()
|
live.stop()
|
||||||
|
|
||||||
|
def live_incremental_response(self, live, final):
|
||||||
|
show_resp = self.modify_incremental_response(final)
|
||||||
|
if not show_resp:
|
||||||
|
return
|
||||||
|
|
||||||
|
md = Markdown(show_resp, style=self.assistant_output_color, code_theme="default")
|
||||||
|
live.update(md)
|
||||||
|
|
||||||
def modify_incremental_response(self):
|
def modify_incremental_response(self):
|
||||||
return self.partial_response_content
|
return self.partial_response_content
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class FunctionCoder(Coder):
|
||||||
else:
|
else:
|
||||||
self.cur_messages += [dict(role="assistant", content=content)]
|
self.cur_messages += [dict(role="assistant", content=content)]
|
||||||
|
|
||||||
def modify_incremental_response(self):
|
def modify_incremental_response(self, final=False):
|
||||||
args = self.parse_partial_args()
|
args = self.parse_partial_args()
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
|
@ -70,7 +70,7 @@ class FunctionCoder(Coder):
|
||||||
if explanation:
|
if explanation:
|
||||||
res += f"{explanation}\n\n"
|
res += f"{explanation}\n\n"
|
||||||
|
|
||||||
for file_upd in files:
|
for i, file_upd in enumerate(files):
|
||||||
path = file_upd.get("path")
|
path = file_upd.get("path")
|
||||||
if not path:
|
if not path:
|
||||||
continue
|
continue
|
||||||
|
@ -79,11 +79,13 @@ class FunctionCoder(Coder):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
res += path + ":\n"
|
res += path + ":\n"
|
||||||
res += self.live_diffs(path, content)
|
|
||||||
|
this_final = (i < len(files) - 1) or final
|
||||||
|
res += self.live_diffs(path, content, this_final)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def live_diffs(self, fname, content):
|
def live_diffs(self, fname, content, final):
|
||||||
lines = content.splitlines(keepends=True)
|
lines = content.splitlines(keepends=True)
|
||||||
|
|
||||||
# ending an existing block
|
# ending an existing block
|
||||||
|
@ -95,7 +97,7 @@ class FunctionCoder(Coder):
|
||||||
show_diff = diffs.diff_partial_update(
|
show_diff = diffs.diff_partial_update(
|
||||||
orig_lines,
|
orig_lines,
|
||||||
lines,
|
lines,
|
||||||
final=True,
|
final,
|
||||||
).splitlines()
|
).splitlines()
|
||||||
|
|
||||||
return "\n".join(show_diff)
|
return "\n".join(show_diff)
|
||||||
|
|
|
@ -43,12 +43,17 @@ def diff_partial_update(lines_orig, lines_updated, final=False):
|
||||||
# dump(lines_orig)
|
# dump(lines_orig)
|
||||||
# dump(lines_updated)
|
# dump(lines_updated)
|
||||||
|
|
||||||
last_non_deleted = find_last_non_deleted(lines_orig, lines_updated)
|
num_orig_lines = len(lines_orig)
|
||||||
|
|
||||||
|
if final:
|
||||||
|
last_non_deleted = num_orig_lines
|
||||||
|
else:
|
||||||
|
last_non_deleted = find_last_non_deleted(lines_orig, lines_updated)
|
||||||
|
|
||||||
# dump(last_non_deleted)
|
# dump(last_non_deleted)
|
||||||
if last_non_deleted is None:
|
if last_non_deleted is None:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
num_orig_lines = len(lines_orig)
|
|
||||||
pct = last_non_deleted * 100 / num_orig_lines
|
pct = last_non_deleted * 100 / num_orig_lines
|
||||||
bar = create_progress_bar(pct)
|
bar = create_progress_bar(pct)
|
||||||
bar = f"! {last_non_deleted:3d} / {num_orig_lines:3d} lines [{bar}] {pct:3.0f}%\n\n"
|
bar = f"! {last_non_deleted:3d} / {num_orig_lines:3d} lines [{bar}] {pct:3.0f}%\n\n"
|
||||||
|
@ -63,12 +68,14 @@ def diff_partial_update(lines_orig, lines_updated, final=False):
|
||||||
diff = list(diff)[2:]
|
diff = list(diff)[2:]
|
||||||
|
|
||||||
diff = "".join(diff)
|
diff = "".join(diff)
|
||||||
|
if not diff.endswith("\n"):
|
||||||
|
diff += "\n"
|
||||||
|
|
||||||
show = "```diff\n"
|
show = "```diff\n"
|
||||||
if not final:
|
if not final:
|
||||||
show += bar
|
show += bar
|
||||||
|
|
||||||
show += diff + "```\n"
|
show += diff + "```\n\n"
|
||||||
|
|
||||||
# print(diff)
|
# print(diff)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue