1. Lock pyte screen initialization in open() to prevent races with
concurrent _update_screen() calls
2. Reorder session registration: call open() BEFORE adding to
sessions/routes dicts, so sessions are fully initialized before
other code can access them
3. Add clarifying comment that PTY resize completes before pyte resize
These fixes prevent dimension mismatches between PTY and pyte screen
that could cause content wrapping in screenshots.
When creating a new session for screenshot:
1. Use width/height query params instead of hardcoded DISCONNECT_RESIZE
2. Add a small delay (0.5s) after creating session to allow initial output
This ensures new sessions are created with the correct dimensions
matching what the screenshot expects.
The screenshot was creating a new pyte screen with arbitrary dimensions
from query params, but the replay buffer contains ANSI sequences meant
for the session's actual terminal size. This mismatch caused wrapping.
Now we use get_screen_state() which returns the actual screen buffer
from the terminal session's pyte screen, with the correct dimensions.
This ensures the screenshot matches exactly what the terminal rendered.
Pyte uses 'brightblack', 'brightred', etc. but Rich expects
'bright_black', 'bright_red' with underscores. Added PYTE_TO_RICH_COLOR
mapping to translate color names in screenshot rendering.
Test fixes:
- Fix app_session.py to use 'textual-webterm' package name (not 'textual-web')
- Fix CLI version test to not hardcode version number
- Fix static path test to not use removed Path._flavour attribute
Removed unused dependencies:
- xdg
- msgpack
- httpx
All 209 tests pass with 86% coverage.
Screenshots now properly preserve terminal colors:
1. Replay buffer provides raw ANSI data with color codes
2. pyte interprets escape sequences for accurate screen state
3. Rich renders the pyte buffer with colors to SVG
This gives us both accurate terminal state (no creeping/wrapping)
and proper color preservation in screenshots.
Bumps version to 0.1.12.
Instead of trying to replay a truncated byte buffer through pyte, this
change maintains a pyte Screen object within TerminalSession that gets
updated as terminal data flows through. This provides accurate terminal
state for screenshots without issues from buffer truncation.
Key changes:
- Add pyte Screen and Stream to TerminalSession
- Update screen state as data arrives via _update_screen()
- Add get_screen_lines() to return current screen state
- Resize pyte screen when terminal size changes
- Update local_server to use get_screen_lines() directly
- Remove _apply_carriage_returns() workaround
This properly fixes the tmux status bar 'creeping up' issue by ensuring
the screenshot always reflects the actual terminal state.
Convert f-string logging to lazy %-style interpolation throughout:
- session_manager.py
- cli.py
- terminal_session.py
This follows Python logging best practices for performance (lazy
evaluation) and consistency across the codebase.
Addresses REFACTORING.md item about normalizing logging style.
Consolidate nested helper functions and reduce complexity:
- Inline header extraction with first_header helper
- Use rpartition for cleaner host:port splitting
- Simplify control flow with loop over header candidates
Addresses REFACTORING.md item about simplifying _get_ws_url_from_request.
Replace try/finally with contextlib.AsyncExitStack for cleaner
structured cleanup of the aiohttp runner. This ensures proper
resource cleanup even in complex shutdown scenarios.
Addresses REFACTORING.md item about TaskGroup/cleanup context.
Replace bare Exception catch with specific exception types:
- json.JSONDecodeError for invalid JSON
- TypeError, KeyError, ValueError for malformed messages
- OSError for I/O errors
Addresses REFACTORING.md item about narrowing WebSocket error handling.
Replaces simple carriage return handling with pyte terminal emulator
to properly interpret all ANSI escape sequences including cursor
positioning. This fixes the tmux status bar 'creeping up' issue in
screenshots.
Adds pyte dependency to pyproject.toml.
Resolves TODO item #2.