mpfaffenberger / mpfaffenberger/code_puppy

reset_unix_terminal() blocks ~1s and captures the escape sequences that were supposed to reset the terminal

Open
#428 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. reset deliberately sleeps ~1 second (it waits for the terminal to settle after re-initialization), so every code path that calls reset_terminal() on macOS/Linux silently stalls the UI for a second.
  2. capture_output=True defeats the purpose: reset works 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 the TERM ioctl side effects. The current behavior is "block one second, change little."
  3. No timeout: if reset hangs (e.g., weird TERM database), 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.