mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
perf: Optimize terminal emulation by checking for "Atuin" first
This commit is contained in:
parent
2d8bc95bae
commit
6bc9daa6ee
1 changed files with 32 additions and 14 deletions
|
@ -29,9 +29,13 @@ def main():
|
||||||
height = header_data.get("height", 24)
|
height = header_data.get("height", 24)
|
||||||
print(f"Terminal dimensions: {width}x{height}")
|
print(f"Terminal dimensions: {width}x{height}")
|
||||||
|
|
||||||
# Initialize terminal emulator
|
# Initialize terminal emulator but don't use it unless necessary
|
||||||
screen = pyte.Screen(width, height)
|
screen = pyte.Screen(width, height)
|
||||||
stream = pyte.Stream(screen)
|
stream = pyte.Stream(screen)
|
||||||
|
|
||||||
|
# Track if we need to check the terminal (if "Atuin" might be on screen)
|
||||||
|
check_terminal = False
|
||||||
|
atuin_chars = set("Atuin")
|
||||||
|
|
||||||
# Process events line by line
|
# Process events line by line
|
||||||
for line in tqdm(fin, desc="Processing events", total=total_lines - 1):
|
for line in tqdm(fin, desc="Processing events", total=total_lines - 1):
|
||||||
|
@ -40,20 +44,34 @@ def main():
|
||||||
|
|
||||||
event = json.loads(line)
|
event = json.loads(line)
|
||||||
|
|
||||||
# Only run terminal emulation for output events
|
# For output events, check for potential "Atuin" content
|
||||||
if len(event) >= 3 and event[1] == "o":
|
if len(event) >= 3 and event[1] == "o":
|
||||||
stream.feed(event[2])
|
output_text = event[2]
|
||||||
|
|
||||||
# Check if "Atuin" is visible on screen - exit early if found
|
# Fast check: if any letters of "Atuin" are in the output
|
||||||
atuin_visible = False
|
if any(char in output_text for char in atuin_chars):
|
||||||
for display_line in screen.display:
|
# Only now feed to terminal emulator
|
||||||
if "Atuin" in display_line:
|
stream.feed(output_text)
|
||||||
atuin_visible = True
|
check_terminal = True
|
||||||
break
|
elif check_terminal:
|
||||||
|
# If we're already checking the terminal, continue feeding
|
||||||
if atuin_visible:
|
stream.feed(output_text)
|
||||||
continue # Skip this event
|
|
||||||
|
# If we need to check the terminal, do so
|
||||||
|
if check_terminal:
|
||||||
|
# Check if "Atuin" is visible on screen
|
||||||
|
atuin_visible = False
|
||||||
|
for display_line in screen.display:
|
||||||
|
if "Atuin" in "".join(display_line):
|
||||||
|
atuin_visible = True
|
||||||
|
break
|
||||||
|
|
||||||
|
# Reset flag if Atuin is no longer visible
|
||||||
|
if not atuin_visible:
|
||||||
|
check_terminal = False
|
||||||
|
else:
|
||||||
|
continue # Skip this event if Atuin is visible
|
||||||
|
|
||||||
# Write event to output file
|
# Write event to output file
|
||||||
fout.write(json.dumps(event) + "\n")
|
fout.write(json.dumps(event) + "\n")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue