Description
Parse exactly one SGR 38/48;2;r;g;b truecolor field with byte channels; no colon syntax, color-space field or terminal gamut guarantee.
Terminal escape sequences can encode cursor commands, text styles and other controls inside ordinary text. SGR changes selected graphic attributes; CSI and OSC tokens have different framing. These tools operate on explicit strings and records, with a deliberately limited parser or style model rather than an emulated screen.1
Parse exactly one SGR 38/48;2;r;g;b truecolor field with byte channels; no colon syntax, color-space field or terminal gamut guarantee.
When to use this tool
Use this tool to parse exactly one SGR 38/48;2;r;g;b truecolor field with byte channels; no colon syntax, color-space field or terminal gamut guarantee.
How to use the tool and how it works
- Enter parameters using the field definitions below.
- Run the operation. Correct input errors before interpreting an output.
- Read result.background, result.rgb. Use the ordering, boundary rules and absence conditions described below.
Require exactly [38 or 48, 2, red, green, blue], with integer color components from 0 through 255. Return the RGB components and background flag.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| parameters | Explicit numeric SGR parameters, in sequence order. | Dense list of at most 128 finite numbers; integer/shape constraints above also apply. |
| Output field | Interpretation |
|---|---|
| result | Object containing the named fields below. |
| result.background | True for a background-color field, false for foreground. |
| result.rgb | Red, green and blue integer components from 0 through 255. |
{
"input": {
"parameters": [
48,
2,
1,
2,
3
]
},
"output": {
"result": {
"background": true,
"rgb": [
1,
2,
3
]
}
}
} Limitations and assumptions
- This parses one extended-color field, not an arbitrary SGR stream or color profile.
- Source spans use zero-based UTF-16 offsets with exclusive ends; byte totals, where returned, use UTF-8. Escape tokens are represented as JSON escapes in the example and are not executed by this description.
- Every declared top-level input field is required and unexpected fields are rejected. Ordinary strings are limited to 8,192 UTF-16 code units and lists to 128 entries, with tighter operation-specific bounds where stated. JSON text has bounded nesting and node counts.
- Numeric outputs must be finite and no larger in absolute magnitude than the safe-integer limit; operations returning exact large integers use decimal text. Positions are zero-based and spans end exclusively unless the operation explicitly states a different convention.
Alternative or Complementary methods
Use token inspection for source offsets and style replay for the supported attributes. A real terminal emulator is needed to determine screen contents, terminal-specific rendering or device behavior.
References
-
ECMA-48: Control Functions for Coded Character Sets — Ecma International
-
Tool behavior and example: Terminal SGR RGB Color Field Parser — tool.io
Similar or alternative tools
- Terminal SGR Indexed Color Field Parser
Parse exactly one SGR 38/48;5;n indexed color field, not an arbitrary SGR stream or terminal palette lookup.
- Terminal SGR Background Color Token
Format an explicit 0–255 indexed SGR background color field; no RGB palette mapping or terminal display guarantee.