-
Notifications
You must be signed in to change notification settings - Fork 211
Description
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
-
Markup parser (
ScreenBuffer.prototype.parseMarkup) usesmisc.markupOptionswhich maps colors to palette indices:'c': { color: 6 }(palette index)
-
ScreenBufferHD.object2attr only handles:
- RGB objects:
{ color: { r, g, b } } - Hex strings:
{ color: '#rrggbb' }
- RGB objects:
-
Palette indices fall through to the
elsebranch:// ScreenBufferHD.js line 857-862 else { attr[ BPOS_R ] = 0 ; attr[ BPOS_G ] = 0 ; attr[ BPOS_B ] = 0 ; attr[ BPOS_A ] = 255 ; }
-
Unused RGB mappings: ScreenBufferHD defines
markupToAttrObjectwith 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 hexSuggested Fix
Either:
- Override
ScreenBufferHD.prototype.parseMarkupto usemarkupToAttrObjectinstead ofmisc.markupOptions - Modify
ScreenBufferHD.object2attrto 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