@nightgrey/ansi
    Preparing search index...

    Class Attributable<T>Abstract

    Attributable

    An abstract class to easily implement your own performant bitset representation to handle SGR attributes.

    class Attributes extends Attributable {
    protected with(
    value?: number,
    bg?: ColorAttribute | null,
    fg?: ColorAttribute | null,
    ul?: ColorAttribute | null,
    ) {
    return new Attributes(
    value ?? this.value,
    bg ?? this.bg,
    fg ?? this.fg,
    ul ?? this.ul,
    );
    }
    }

    const attributes = new Attributes()
    .foregroundColor(BasicColor.Red)
    .underline()
    .bold()
    .italic();

    attributes.has(1 << Bit.Bold); // true
    attributes.has(1 << Bit.Italic); // true
    attributes.has(1 << Bit.Underline); // true
    attributes.has(1 << Bit.ForegroundColor); // true


    attributes.and(new Attributes().backgroundColor(BasicColor.Blue));
    attributes.or(new Attributes().backgroundColor(BasicColor.Blue));
    attributes.xor(new Attributes().backgroundColor(BasicColor.Blue));

    Attributes for a concrete implementation

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    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.

    Accessors

    Methods

    • 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 T

      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 T

      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 T

      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,
      );
      }