Skip to content

sliceEndToWidth

sliceEndToWidth(text, maxWidth): string

Defined in: packages/core/src/utils/displayWidth.ts:287

The longest TRAILING run of whole clusters whose total width is at most maxWidth — i.e. keep the tail, lose the head. The mirror of sliceToWidth, for values whose end is the informative part (a path’s leaf directory).

This one materialises the pieces: it walks backwards, and both cluster and sequence boundaries are only derivable from the front. Its callers pass a path or a model id, so the input is a line rather than a file.

Keeping the END means the escapes that OPENED a style sit in the discarded head and go with it, so a tail comes back in the terminal’s default styling. Only the sequences inside the kept span are carried, which leaves the tail ending in whatever state the whole string ended in — the cut introduces no bleed of its own.

string

number

string