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.