Formatting

_wrap_ansi_text(text, width)[source]

Wrap text that contains ANSI escape sequences.

This function strips ANSI codes for width calculation but preserves them in the output.

Return type:

str

truncate(text, placeholder='')[source]

Truncates the input string to fit the terminal width.

Return type:

str

Parameters:
  • text (str) – The input string.

  • placeholder (str) – The placeholder string to use when truncating.

Returns:

The truncated string.

Return type:

str

wrap(text)[source]

Wraps the input string at whitespace boundaries to fit the terminal width. This function is ANSI-aware and will not break ANSI escape sequences.

Return type:

str

Parameters:

text (str) – The input string.

Returns:

The wrapped string.

Return type:

str