-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Problem / Background
When running Neovim after connecting via SSH, strange text appears at the bottom of the screen:
:159c/16e0/18490+r54631+r524742=380+r736574726762660+r736574726762621$r0;48:2:1:1:2:3m1+r4D73=1B5D35323B25703125733B257032257307
This occurs because terminal escape sequence responses are not being properly handled.
Root Cause Analysis
The displayed text consists of raw terminal escape sequence responses:
+rpattern: XTGETTCAP response (terminal capability query response)736574726762-> hex decoded: "setrgb" (true color support query)48:2:1:1:2:3m: SGR true color escape sequence1B5D35323B...: OSC (Operating System Command) sequence
When Neovim starts, it sends several queries to detect terminal capabilities:
- XTGETTCAP (terminfo capability query)
- DA1/DA2/DA3 (Device Attributes)
- Kitty keyboard protocol support
- True color support
When PTY is not properly configured in SSH sessions, or terminal responses are mixed with stdout, raw sequences appear on screen.
Proposed Solution
- Properly configure terminal modes during PTY allocation (raw mode, echo settings, etc.)
- Correctly pass terminal type (TERM environment variable)
- Properly handle terminal query/response cycles in SSH channel
- Improve PTY settings for interactive sessions
Acceptance Criteria
- Neovim launches cleanly without displaying raw escape sequences
- Terminal capability queries are properly handled in the PTY layer
- TERM environment variable is correctly propagated to remote session
- Interactive applications (vim, htop, etc.) work without visual artifacts
- Raw terminal responses do not leak into visible output
Technical Considerations
- Review PTY allocation in
src/ssh/modules - Ensure proper terminal mode flags (ECHO, ICANON, etc.) are set
- Consider handling XTGETTCAP and DA responses at the SSH client level
- May need to buffer and filter terminal responses before display
Implementation (PR #77)
The fix adds an escape sequence filter module (escape_filter.rs) that uses a state machine to:
- Filter XTGETTCAP responses (
\x1bP+r...) - Filter DA1/DA2/DA3 responses (
\x1b[?...c) - Filter OSC responses (
\x1b]...) - Filter DCS responses (
\x1bP...) - Preserve valid escape sequences for colors, cursor movement, etc.
Additionally, TERM and COLORTERM environment variables are now set before PTY allocation.
Additional Context
Related closed issues:
- feat: Implement true PTY allocation for interactive mode #24: feat: Implement true PTY allocation for interactive mode
- PTY mode: sudo password input fails in interactive sessions #40: PTY mode: sudo password input fails in interactive sessions
This issue may require revisiting the PTY implementation to ensure proper terminal emulation.