mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 04:55:58 +03:00
[PR #559] feat(core): add indexed color (0-255) and OSC palette control #620
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#620
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/559
Author: @bresilla
Created: 1/20/2026
Status: 🔄 Open
Base:
main← Head:feat/indexed-colors📝 Commits (8)
e14abdafeat: Add 256-color palette and metadata to RGBAec7cf26feat: Add RGB_META field to RGBA type4cacd74feat: enable indexed colors and RGB_META in RGBA struct225ef4ffeat: adjust test for the new [5]th float01758a1fix: Addmetafield toExternalCursorState73eebd8feat: Add support for indexed colors in RGBA in TS sideb8f6e6ctest: add ANSI 256 color showcase exampled98b815fix: Use 16-color ANSI escape codes for indexed colors 0-15 in renderer📊 Changes
30 files changed (+869 additions, -448 deletions)
View changed files
📝
packages/core/src/buffer.ts(+4 -4)➕
packages/core/src/examples/terminal_ansi.ts(+197 -0)📝
packages/core/src/lib/RGBA.test.ts(+9 -2)📝
packages/core/src/lib/RGBA.ts(+74 -4)📝
packages/core/src/post/filters.ts(+28 -28)📝
packages/core/src/renderables/Text.selection-buffer.test.ts(+4 -4)📝
packages/core/src/renderables/Text.test.ts(+6 -6)📝
packages/core/src/renderables/TextTable.test.ts(+2 -2)📝
packages/core/src/renderables/__tests__/LineNumberRenderable.test.ts(+10 -10)📝
packages/core/src/renderables/__tests__/Textarea.scroll.test.ts(+1 -1)📝
packages/core/src/renderables/__tests__/Textarea.selection.test.ts(+17 -17)📝
packages/core/src/testing/test-recorder.test.ts(+2 -2)📝
packages/core/src/zig-structs.ts(+2 -1)📝
packages/core/src/zig.ts(+1 -1)📝
packages/core/src/zig/ansi.zig(+124 -2)📝
packages/core/src/zig/bench/buffer-draw-text-buffer_bench.zig(+15 -15)📝
packages/core/src/zig/bench/styled-text_bench.zig(+18 -18)📝
packages/core/src/zig/buffer.zig(+39 -32)📝
packages/core/src/zig/lib.zig(+2 -0)📝
packages/core/src/zig/renderer.zig(+38 -23)...and 10 more files
📄 Description
Summary
Adds full support for terminal indexed colors (0-255) and OSC-based terminal palette control, enabling the use of the standard 256-color palette and dynamic color modification via ANSI/OSC escape sequences.
Makes this possible (with tools like pywal et al):

Changes
TypeScript (RGBA.ts)
COLOR_TYPE_RGB,COLOR_TYPE_INDEXED,COLOR_TYPE_DEFAULTconstantsRGBAclass withcolorType,indexpropertiesRGBA.fromIndex(index),RGBA.defaultForeground(),RGBA.defaultBackground()static methodsisIndexed(),isDefault(),isRgb()instance methodsindexToApproximateRgb()function with standard 256-color palette mappingColorInputtype to acceptstring | RGBA | IndexedColor | numberparseColor()to handle"ansi:N"format, numeric indices, and{index: N}objectsTypeScript (terminal-palette.ts) - OSC Palette Control
setPaletteColor(index, hex)- dynamically set any of the 256 palette colors (OSC 4)setForeground(hex)- set terminal default foreground color (OSC 10)setBackground(hex)- set terminal default background color (OSC 11)setCursorColor(hex)- set cursor color (OSC 12)resetPaletteColor(index)- reset palette color to terminal default (OSC 104)resetForeground()- reset foreground to default (OSC 110)resetBackground()- reset background to default (OSC 111)resetCursorColor()- reset cursor color to default (OSC 112)Zig (ansi.zig)
ColorTypeenum:rgb,indexed,defaultColorstruct combining RGBA with type and indexindexToApproximateRgba(),fgIndexedColorOutput(),bgIndexedColorOutput()fgDefaultOutput(),bgDefaultOutput()for default color resetZig (buffer.zig)
Cellstruct withfg_color_type,bg_color_type,fg_index,bg_indexOptimizedBufferZig (renderer.zig)
\x1b[38;5;Nm/\x1b[48;5;Nmfor indexed colors\x1b[39m/\x1b[49mfor default colorsUsage Examples
Indexed Colors
OSC Palette Control
Testing
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.