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