Skip to main content

Module cursor

Module cursor 

Source
Expand description

Prompt cursor coordinate calculation.

Given prompt text, a grapheme-cluster cursor position, the body width (columns available for text), and an optional prompt indent, compute the (row, col) coordinate of the cursor within the prompt’s visual rows.

Uses unicode_width for display-width measurement so that wide characters (CJK), zero-width characters (combining marks), and emoji are handled correctly. Cursor position is expressed as a grapheme-cluster index (matching crate::input::PromptInput).

Handles:

  • single-line input;
  • word/char wrapping at body_width using display width, not char count;
  • explicit \n newlines;
  • a leading prompt indent applied to every visual row;
  • multibyte and grapheme clusters.

Functions§

prompt_cursor
Compute the (row, col) coordinate of the cursor in the prompt’s visual rows.
prompt_rows
Decompose prompt text into visual rows of text (without the indent) for rendering. Uses display width for wrapping so wide characters occupy the correct number of columns.