Skip to content

Avoid redundant renderer resets during application lifecycle - #2079

Open
deepakganesh78 wants to merge 2 commits into
prompt-toolkit:mainfrom
deepakganesh78:fix/redundant-renderer-resets
Open

Avoid redundant renderer resets during application lifecycle#2079
deepakganesh78 wants to merge 2 commits into
prompt-toolkit:mainfrom
deepakganesh78:fix/redundant-renderer-resets

Conversation

@deepakganesh78

@deepakganesh78 deepakganesh78 commented Jul 25, 2026

Copy link
Copy Markdown

Fixes #1967.

Summary

  • track whether the renderer currently owns terminal state that needs cleanup
  • skip renderer resets during Application initialization and first startup, when nothing has rendered yet
  • avoid the duplicate fallback reset after a successful final render
  • add lifecycle regression coverage for startup/shutdown reset counts and a full-screen resize redraw failure that must still quit the alternate screen

Validation

  • uv run pytest -q tests/test_application.py tests/test_vt100_output.py — 4 passed
  • uv run prek run --files src/prompt_toolkit/application/application.py src/prompt_toolkit/renderer.py tests/test_application.py — passed
  • uv run pytest -q tests/ — 148 passed, 5 skipped; 4 Windows/non-console failures reproduced unchanged on main (two history-input timing assertions and two NoConsoleScreenBufferError failures)
  • targeted mypy reports the same existing trace-callback signature errors at application.py:1119, :1123, and :1126
  • GitHub Actions unit tests — 158 passed on every Python 3.10–3.14t job; jobs currently stop at the same three pre-existing mypy trace-callback errors reproduced on unmodified main

deepakganesh78 and others added 2 commits July 25, 2026 16:10
Track whether the renderer has produced terminal state so application resets only clean up when needed. Add a lifecycle regression test covering startup and shutdown reset counts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep renderer cleanup pending when a resize reset intentionally retains the alternate screen. Cover a failed full-screen redraw after resize to ensure final cleanup quits the alternate screen.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deepakganesh78

Copy link
Copy Markdown
Author

Addressed the resize/alternate-screen lifecycle review in e2c21a7.

Renderer.reset(leave_alternate_screen=False) now keeps cleanup pending while _in_alternate_screen remains active. The new full-screen regression test schedules a resize, forces the resize redraw to fail before Renderer.render(), and verifies final cleanup still quits the alternate screen.

Validation:

  • uv run pytest -q tests/test_application.py tests/test_vt100_output.py — 4 passed
  • uv run prek run --files src/prompt_toolkit/renderer.py tests/test_application.py — passed
  • the regression test fails against the previous behavior with alternate_screen_quit == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renderer.reset is called 3 times during application startup.

1 participant