@nightgrey/ansi
    Preparing search index...

    Class Style

    An immutable class for styling text.

    const style = new Style()
    .foregroundColor(BasicColor.Red)
    .underline()
    .bold()
    .italic();

    // Renders "Hello World!" with the style attributes
    style.format("Hello World!"); // "\x1b[31;4;1;3mHello World!\x1b[m"

    // Renders the SGR escape sequence
    style.toString(); // "\x1b[31;4;1;3m"

    // Renders the JSON representation of the style
    style.toJSON(); // { foregroundColor: BasicColor.Red, underline: true, bold: true, italic: true }

    // Create a style from an object of attributes properties
    Style.from({ foregroundColor: BasicColor.Green, underline: true, bold: true, italic: true });

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionalattributes: number
      • Optionalbackground: null | number
      • Optionalforeground: null | number
      • Optionalunderline: null | number

      Returns Style

    Properties

    "[toStringTag]": string = "Attributable"
    bg: null | number

    Background color

    Either an ANSI indexed color (0-255) or a packed RGB.

    0
    
    (255 << 8) | (255 << 16) | (255 << 24)
    
    fg: null | number

    Foreground color

    Either an ANSI indexed color (0-255) or a packed RGB.

    1
    
    (255 << 8) | (255 << 16) | (255 << 24)
    
    ul: null | number

    Underline color

    Either an ANSI indexed color (0-255) or a packed RGB.

    2
    
    (255 << 8) | (255 << 16) | (255 << 24)
    
    value: number

    Attributes

    A bitset representening the set attributes.

    empty: Style = ...

    Accessors

    Methods

    • Formats a string with this style applied.

      Parameters

      • string: string

      Returns string

    • Set a bit at the specified position

      Parameters

      • bit: Bit

        The bit position (0-63)

      • Optionalbg: number

        background color

      • Optionalfg: number

        foreground color

      • Optionalul: number

        underline color

      Returns Style

      A new Attributable instance with the bit set

    • Unset a bit at the specified position

      Parameters

      • bit: Bit

        The bit position (0-63)

      • Optionalbg: number

        background color

      • Optionalfg: number

        foreground color

      • Optionalul: number

        underline color

      Returns Style

      A new Attributable instance with the bit unset

    • Return a new Attributable instance with the given parameters.

      Parameters

      • Optionalattributes: number

        Next value of the attributable

      • Optionalbackground: null | number

        Next background color

      • Optionalforeground: null | number

        Next foreground color

      • Optionalunderline: null | number

        Next underline color

      Returns Style

      function with(
      attributes?: number,
      background?: ColorAttribute | null,
      foreground?: ColorAttribute | null,
      underline?: ColorAttribute | null,
      ) {
      return new Attributes(
      attributes ?? this.value,
      background === null ? null : background || this.bg,
      foreground === null ? null : foreground || this.fg,
      underline === null ? null : underline || this.ul,
      );
      }