Skip to content

Main content

Terminal SGR Parameter List Parser

Parse one seven-bit ESC[ semicolon-only SGR token with empty parameters defaulting to zero; no colon subparameters, C1 CSI or unsupported numeric ranges.

Loading tool…

Description

Parse one seven-bit ESC[ semicolon-only SGR token with empty parameters defaulting to zero; no colon subparameters, C1 CSI or unsupported numeric ranges.

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 one seven-bit ESC[ semicolon-only SGR token with empty parameters defaulting to zero; no colon subparameters, C1 CSI or unsupported numeric ranges.

When to use this tool

Use this tool to parse one seven-bit ESC[ semicolon-only SGR token with empty parameters defaulting to zero; no colon subparameters, C1 CSI or unsupported numeric ranges.

How to use the tool and how it works

  1. Enter token using the field definitions below.
  2. Run the operation. Correct input errors before interpreting an output.
  3. Read result.parameters. Use the ordering, boundary rules and absence conditions described below.

Require one complete ESC-bracket numeric-semicolon m token. Convert empty parameters to zero and return numeric parameters from 0 through 255.2

Input fieldMeaning and unitsAccepted input
tokenOne complete escape token in the supported syntax; JSON shows ESC as an escaped character.Text, at most 8,192 UTF-16 code units; the operation’s grammar also applies.
Output fieldInterpretation
resultObject containing the named fields below.
result.parametersNumeric SGR parameter sequence in the stated order.
json
{
  "input": {
    "token": "\u001b[1;31m"
  },
  "output": {
    "result": {
      "parameters": [
        1,
        31
      ]
    }
  }
}

Limitations and assumptions

  • Parsing the numeric token does not establish that every parameter is supported by the style-replay tool.
  • 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

  1. ECMA-48: Control Functions for Coded Character Sets — Ecma International

  2. Tool behavior and example: Terminal SGR Parameter List Parser — tool.io

Similar or alternative tools