Class TerminalString

Implements concatenation of strings that can be printed on a terminal.

Constructors

  • Creates a terminal string.

    Parameters

    • indent: number = 0

      The starting column for this string (negative values are replaced by zero)

    • breaks: number = 0

      The initial number of line feeds (non-positive values are ignored)

    • rightAlign: boolean = false

      True if the string should be right-aligned to the terminal width

    Returns TerminalString

Properties

context: TerminalContext

The terminal string context.

indent: number = 0

The starting column for this string (negative values are replaced by zero)

Accessors

Methods

  • Appends a text that may contain control characters or sequences to the list.

    Parameters

    • text: string

      The text to be appended

    • length: number

      The length of the text without control characters or sequences

    Returns this

    The terminal string instance

  • Appends line breaks to the list.

    Parameters

    • count: number = 1

      The number of line breaks to insert (non-positive values are ignored)

    Returns this

    The terminal string instance

  • Appends an SGR clear sequence to the list. This is different from the pop method (we are aware of this ambiguity, but we want method names to be short).

    Returns this

    The terminal string instance

  • Appends a word that is merged with the last word.

    Parameters

    • word: string

      The closing word

    Returns this

    The terminal string instance

  • Appends a word that will be merged with the next word.

    Parameters

    • word: string

      The opening word

    • pos: number = NaN

      The position of a previously added word

    Returns this

    The terminal string instance

  • Appends another terminal string to the list. We deliberately avoided optimizing this code, in order to keep it short.

    Parameters

    Returns this

    The terminal string instance

  • Removes strings from the end of the list.

    Parameters

    • count: number = 1

      The number of strings

    Returns this

    The terminal string instance

  • Sets a flag to merge the next word to the last word.

    Parameters

    • merge: boolean = true

      The flag value (defaults to true)

    Returns this

    The terminal string instance

  • Splits a text into words and style sequences, and appends them to the list.

    Parameters

    • text: string

      The text to be split

    • Optional format: FormatCallback<string>

      An optional callback to process format specifiers

    Returns this

    The terminal string instance

  • Appends a word with surrounding styles.

    Parameters

    • begin: Style

      The starting style

    • word: string

      The word to be appended

    • end: Style = ''

      The ending style (optional)

    Returns this

    The terminal string instance

  • Appends a word to the list.

    Parameters

    • word: string

      The word to be appended. Should not contain control characters or sequences.

    Returns this

    The terminal string instance

  • Wraps the internal strings to fit in a terminal width.

    Parameters

    • result: string[]

      The resulting strings to append to

    • column: number

      The current terminal column

    • width: number

      The desired terminal width (or zero to avoid wrapping)

    • emitStyles: boolean

      True if styles should be emitted

    Returns number

    The updated terminal column