Class AnsiString

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

Constructors

  • Creates a ANSI 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)

    • righty: boolean = false

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

    • defSty: Style = ...

      The default style to use (defaults to none)

    Returns AnsiString

Properties

defSty: Style = ...

The default style to use (defaults to none)

indent: number = 0

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

righty: boolean = false

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

Accessors

  • set merge(merge: boolean): void

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

    Parameters

    • merge: boolean

      The flag value

    Returns void

Methods

  • Appends a text.

    Parameters

    • text: string

      The text with no control sequences

    • styledText: string

      The text with possible control sequences

    • close: boolean = false

      True if the text should be merged with the previous string, if any

    Returns this

    The ANSI string instance

  • Appends line breaks.

    Parameters

    • count: number = 1

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

    Returns this

    The ANSI string instance

  • Closes with a word.

    Parameters

    • word: string

      The word to insert (should contain no styles)

    Returns this

    The ANSI string instance

  • Formats a text from a custom phrase with a set of arguments.

    Parameters

    • phrase: string

      The message phrase

    • flags: FormattingFlags = {}

      The formatting flags

    • ...args: Args

      The message arguments

    Returns this

    The ANSI string instance

  • Opens with a word.

    Parameters

    • word: string

      The word to insert (should contain no styles)

    Returns this

    The ANSI string instance

  • Prepends text to the string at a specific position. This can only be done if the affected string does not contain opening styles.

    Parameters

    • text: string

      The opening text

    • pos: number

      The position of the previously added string

    Returns this

    The ANSI string instance

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

    Parameters

    • text: string

      The text to be split

    • Optionalformat: FormatCallback<string>

      An optional callback to process placeholders

    Returns this

    The ANSI string instance

  • Appends a word.

    Parameters

    • word: string

      The word to insert (should contain no styles)

    • Optionalsty: Style

      The style to be applied

    Returns this

    The ANSI 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

    • emitSpaces: boolean

      True if spaces should be emitted instead of move sequences

    Returns number

    The updated terminal column