Description
Plan supported SGR style-group deltas between complete explicit records, resetting/reapplying shared intensity group as needed; not guaranteed minimal byte encoding.
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
Plan supported SGR style-group deltas between complete explicit records, resetting/reapplying shared intensity group as needed; not guaranteed minimal byte encoding.
When to use this tool
Use this tool to plan supported SGR style-group deltas between complete explicit records, resetting/reapplying shared intensity group as needed; not guaranteed minimal byte encoding.
How to use the tool and how it works
- Enter fromJson, toJson using the field definitions below. For JSON text, serialize the explicit records in the shown shape.
- Run the operation. Correct input errors before interpreting an output.
- Read result.parameters. Use the ordering, boundary rules and absence conditions described below.
Compare the two complete style records. Emit parameter changes, resetting bold and faint together before enabling their desired states.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| fromJson | JSON text encoding {bold: boolean, faint: boolean, italic: boolean, underline: boolean, inverse: boolean, strike: boolean, foreground: string, background: string}. Keep the record keys and value types shown in the decoded example below. A style has boolean bold, faint, italic, underline, inverse and strike fields, and foreground/background colors spelled default, index:N or rgb:R:G:B with canonical byte components. | Text, at most 8,192 UTF-16 code units; the operation’s grammar also applies. |
| toJson | JSON text encoding {bold: boolean, faint: boolean, italic: boolean, underline: boolean, inverse: boolean, strike: boolean, foreground: string, background: string}. Keep the record keys and value types shown in the decoded example below. A style has boolean bold, faint, italic, underline, inverse and strike fields, and foreground/background colors spelled default, index:N or rgb:R:G:B with canonical byte components. | Text, at most 8,192 UTF-16 code units; the operation’s grammar also applies. |
These are the decoded structures used in the example’s JSON text fields. Supply the corresponding serialized JSON strings as input.
{
"fromJson": {
"bold": false,
"faint": false,
"italic": false,
"underline": false,
"inverse": false,
"strike": false,
"foreground": "default",
"background": "default"
},
"toJson": {
"bold": true,
"faint": false,
"italic": false,
"underline": false,
"inverse": false,
"strike": false,
"foreground": "default",
"background": "default"
}
} | Output field | Interpretation |
|---|---|
| result | Object containing the named fields below. |
| result.parameters | Numeric SGR parameter sequence in the stated order. |
{
"input": {
"fromJson": "{\"bold\": false, \"faint\": false, \"italic\": false, \"underline\": false, \"inverse\": false, \"strike\": false, \"foreground\": \"default\", \"background\": \"default\"}",
"toJson": "{\"bold\": true, \"faint\": false, \"italic\": false, \"underline\": false, \"inverse\": false, \"strike\": false, \"foreground\": \"default\", \"background\": \"default\"}"
},
"output": {
"result": {
"parameters": [
22,
1
]
}
}
} Limitations and assumptions
- The plan follows this fixed supported style model and is not guaranteed to be the shortest possible sequence.
- 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 Delta Plan — 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 Span Map
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.