Description
Map plain-text spans to replayed supported SGR style records with original UTF-16 offsets; any non-SGR escape or incomplete control rejects, no terminal execution.
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
Map plain-text spans to replayed supported SGR style records with original UTF-16 offsets; any non-SGR escape or incomplete control rejects, no terminal execution.
When to use this tool
Use this tool to map plain-text spans to replayed supported SGR style records with original UTF-16 offsets; any non-SGR escape or incomplete control rejects, no terminal execution.
How to use the tool and how it works
- Enter text using the field definitions below.
- Run the operation. Correct input errors before interpreting an output.
- Read result.spans. Use the ordering, boundary rules and absence conditions described below.
Start with default style, process supported SGR tokens in order, and attach each resulting style to the intervening text’s UTF-16 source spans.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| text | Source text or visible text, including actual escape characters where the operation inspects them. | Text, at most 8,192 UTF-16 code units; the operation’s grammar also applies. |
| Output field | Interpretation |
|---|---|
| result | Object containing the named fields below. |
| result.spans | Non-control text spans with the style active over each UTF-16 source interval. |
{
"input": {
"text": "a\u001b[31mb"
},
"output": {
"result": {
"spans": [
{
"start": 0,
"end": 1,
"style": {
"bold": false,
"faint": false,
"italic": false,
"underline": false,
"inverse": false,
"strike": false,
"foreground": "default",
"background": "default"
}
},
{
"start": 6,
"end": 7,
"style": {
"bold": false,
"faint": false,
"italic": false,
"underline": false,
"inverse": false,
"strike": false,
"foreground": "index:1",
"background": "default"
}
}
]
}
}
} Limitations and assumptions
- Unsupported, incomplete or non-SGR escape tokens cause an error; this does not render a terminal screen.
- 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 Style Span Map — tool.io
Similar or alternative tools
- Terminal SGR Normalized Style Replay
Replay the documented finite SGR subset from default style: intensity, italic, underline, inverse, strike, basic/indexed/RGB colors; unsupported codes reject instead of being guessed.
- Terminal SGR Style Delta Plan
Plan supported SGR style-group deltas between complete explicit records, resetting/reapplying shared intensity group as needed; not guaranteed minimal byte encoding.