mpfaffenberger / mpfaffenberger/code_puppy
reset_unix_terminal() blocks ~1s and captures the escape sequences that were supposed to reset the terminal
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
Problem
reset_unix_terminal() in code_puppy/terminal_utils.py:129-141 runs the external reset command on every non-Windows "cross-platform reset":
def reset_unix_terminal() -> None:
...
try:
subprocess.run(["reset"], check=True, capture_output=True)
except (subprocess.CalledProcessError, FileNotFoundError):
pass
Problems:
resetdeliberately sleeps ~1 second (it waits for the terminal to settle after re-initialization), so every code path that callsreset_terminal()on macOS/Linux silently stalls the UI for a second.capture_output=Truedefeats the purpose:resetworks by writing terminal-initialization escape sequences to its stdout/stderr — capturing them means they never reach the terminal, so the call mostly doesn't reset anything except via theTERMioctl side effects. The current behavior is "block one second, change little."- No timeout: if
resethangs (e.g., weirdTERMdatabase), the app hangs with it.
Suggested fix
Prefer stty sane plus an ANSI soft-reset written directly to the tty — instant, no subprocess oddities:
def reset_unix_terminal() -> None:
if platform.system() == "Windows":
return
try:
subprocess.run(["stty", "sane"], check=False, timeout=2,
stdin=sys.stdin) # stty needs the tty on stdin
sys.stdout.write("\x1b[!p\x1b[?25h") # DECSTR soft reset + show cursor
sys.stdout.flush()
except (OSError, subprocess.TimeoutExpired):
pass # best-effort
If full reset semantics are truly needed somewhere, give it timeout= and let its output reach the terminal (don't capture).
Filed by Zen Reviewer C (code-puppy-60635a)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in code_puppy/terminal_utils.py:129-141 and inspect reset_unix_terminal(), then trace callers of reset_terminal() to understand when the delay affects the UI. Verify the Unix reset path no longer captures terminal output or waits unnecessarily, remains best-effort on failures, and does not change Windows behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100