refactor: Simplify JSON parsing logic in redact-cast.py

This commit is contained in:
Paul Gauthier 2025-03-13 16:19:29 -07:00 committed by Paul Gauthier (aider)
parent f3d4c931f5
commit 693a43efc8

View file

@ -45,19 +45,22 @@ def main():
# Fast initial check on raw line before JSON parsing
raw_line_has_atuin_chars = any(char in line for char in atuin_chars)
# Only parse JSON if we're checking terminal or need to check
if check_terminal or raw_line_has_atuin_chars:
event = json.loads(line)
# For output events, check for potential "Atuin" content
if len(event) >= 3 and event[1] == "o":
output_text = event[2]
# Only start checking terminal if we found Atuin chars
if raw_line_has_atuin_chars:
check_terminal = True
if check_terminal:
# Only parse JSON if we're checking terminal or need to check
if not check_terminal:
fout.write(line)
continue
event = json.loads(line)
if not (len(event) >= 3 and event[1] == "o"):
fout.write(line)
continue
output_text = event[2]
stream.feed(output_text)
# Check if "Atuin" is visible on screen
@ -68,15 +71,9 @@ def main():
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
check_terminal = atuin_visible
# Write event to output file for non-skipped events
fout.write(line)
else:
# No need to parse JSON if we're not checking terminal
if not atuin_visible:
fout.write(line)