Skip to content

Slow prompt display (~2s) with terminals that don't respond to cursor position queries #1010

@po-nuvai

Description

@po-nuvai

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

  1. 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

  2. Configuration option: Add a way to disable cursor position queries entirely for problematic terminals (e.g., Reedline::disable_cursor_position_query() or similar)

  3. Environment variable: Check for something like REEDLINE_NO_CURSOR_QUERY=1 to skip the query

  4. Lazy/cached querying: Only query cursor position when absolutely necessary, and cache the result

Reproduction

  1. Use Termius Android app to SSH into a machine with nushell as the login shell
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions