-
Notifications
You must be signed in to change notification settings - Fork 197
Description
Description
Some terminal emulators don't properly respond to CSI 6n (Device Status Report) cursor position queries, causing a ~2 second delay on every prompt display.
This was reported in nushell/nushell#17210 by a user experiencing 2-second delays when using Termius on Android to SSH into machines with nushell as the login shell.
Root Cause
In src/painting/painter.rs:174, initialize_prompt_position() calls:
let prompt_selector = select_prompt_row(suspended_state, cursor::position()?);This cursor::position() (from crossterm) sends a CSI 6n escape sequence and waits for the terminal to respond with the cursor position. If the terminal doesn't respond, crossterm times out after ~2 seconds.
Since initialize_prompt_position() is called at the start of every read_line(), this delay happens on every prompt display, not just startup.
Affected Terminals
- Termius on Android - doesn't respond to CSI 6n queries (the reported case)
- Potentially other mobile/embedded terminal emulators
Note: Termius on Linux works fine, as does OpenSSH from Termux on the same Android device.
Suggested Solutions
-
Shorter timeout with fallback: Reduce the timeout for
cursor::position()and fall back to assuming position (0, 0) or tracking position internally when the query fails/times out -
Configuration option: Add a way to disable cursor position queries entirely for problematic terminals (e.g.,
Reedline::disable_cursor_position_query()or similar) -
Environment variable: Check for something like
REEDLINE_NO_CURSOR_QUERY=1to skip the query -
Lazy/cached querying: Only query cursor position when absolutely necessary, and cache the result
Reproduction
- Use Termius Android app to SSH into a machine with nushell as the login shell
- Observe ~2 second delay after every command before the prompt appears
The delay shows up in nushell's perf logging as:
setup reedline took 2.001272815s
References
- Original issue: Slow startup - "setup reedline" - using Termius on Android nushell#17210
- Crossterm cursor position implementation uses a blocking read with timeout
- Similar issues exist in other shells/editors with terminals that don't respond to DSR queries