Skip to main content

Module width

Module width 

Source

Functions§

display_width
Terminal column width of a string, CJK-aware.
slice_cols
Slice s starting at display column start_col, taking up to max_cols columns. Characters that straddle the start boundary are skipped. Used to implement horizontal scroll in the input prompt — keeps the cursor visible when the buffer exceeds the viewport width.
truncate_path
Truncate a file-system path to max_cols display columns, using a path-aware strategy that preserves the last segment (the project or folder name — the most useful bit) and replaces leading segments with .../. Both / and \ are treated as separators.
truncate_to_width
Truncate s so its display width is at most max_cols. Guaranteed to return a valid UTF-8 string that never splits a grapheme.
truncate_with_ellipsis
Truncate s to max_cols display columns, appending when truncation happened so the reader sees a visible “there was more” marker instead of a silent cut mid-word. Reserves 1 column for the ellipsis, so the actual content slice is max_cols - 1 cols wide. Strings that already fit are returned unchanged.
wrap_line_to_width
Split a line (possibly containing SGR escape sequences) into chunks whose visible display width is at most max_cols. SGR bytes pass through without consuming display columns. Handles CJK/emoji width.
wrap_with_cursor
Wrap text to max_cols columns AND locate the cursor’s 2D position within the wrapped layout. Honours explicit \n as a hard line break (Shift+Enter in the input buffer). Returns (lines, cursor_row, cursor_col) where cursor_row is 0-based within lines and cursor_col is the display column within that row.