Skip to content

ScreenBufferHD: Color markup produces RGB(0,0,0) instead of palette colors #265

@KJ7LNW

Description

@KJ7LNW

Description

ScreenBufferHD color markup (^c, ^C, ^r, ^R, etc.) produces black RGB(0,0,0) instead of the expected palette colors. Style markup (^+, ^-, etc.) works correctly.

Expected Behavior

new termkit.Text({
  parent: document,
  content: '^C^+Cyan^:',
  contentHasMarkup: true,
  attr: TERMINAL_DEFAULT_ATTR,
  x: 0, y: 0
});

Should produce RGB(0, 255, 255) with alpha=255 in the ScreenBufferHD buffer.

Actual Behavior

Produces RGB(0, 0, 0) with alpha=255. The text appears black instead of cyan.

(( n.b., alpha handling is the only indication of whether a color is actually to be rendered as color or if it is default, so please make sure any change keeps alpha=0 means default and alpha=255 means render via RGB.

Either that or make sure there's some other mechanism to know if it is a default or not, because we need to differentiate between black background on white foreground meaning terminal default, or meaning actually strictly white foreground with a black background. The current alpha behavior is fine, just making sure we don't lose the meaning of what that does when this bug gets fixed.))

Root Cause

  1. Markup parser (ScreenBuffer.prototype.parseMarkup) uses misc.markupOptions which maps colors to palette indices:

    • 'c': { color: 6 } (palette index)
  2. ScreenBufferHD.object2attr only handles:

    • RGB objects: { color: { r, g, b } }
    • Hex strings: { color: '#rrggbb' }
  3. Palette indices fall through to the else branch:

    // ScreenBufferHD.js line 857-862
    else {
      attr[ BPOS_R ] = 0 ;
      attr[ BPOS_G ] = 0 ;
      attr[ BPOS_B ] = 0 ;
      attr[ BPOS_A ] = 255 ;
    }
  4. Unused RGB mappings: ScreenBufferHD defines markupToAttrObject with RGB color mappings (line 147-170) but this property is never referenced in the codebase.

Workaround

Use explicit RGB color objects instead of markup:

// Works correctly
attr: { color: { r: 0, g: 255, b: 255 } }  // Cyan
attr: { color: '#00ffff' }                 // Cyan hex

Suggested Fix

Either:

  1. Override ScreenBufferHD.prototype.parseMarkup to use markupToAttrObject instead of misc.markupOptions
  2. Modify ScreenBufferHD.object2attr to handle palette index numbers by looking them up in a color scheme

Environment

  • terminal-kit: 3.1.2
  • Node.js: Latest
  • Using ScreenBufferHD with Document Model

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions