Skip to content

Main content

Terminal Style Record Run Compactor

Compact adjacent complete supported terminal-style records after validated normalized style comparison; explicit text only, no escape scanning or terminal rendering.

Loading tool…

Description

Compact adjacent complete supported terminal-style records after validated normalized style comparison; explicit text only, no escape scanning or terminal rendering.

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

Compact adjacent complete supported terminal-style records after validated normalized style comparison; explicit text only, no escape scanning or terminal rendering.

When to use this tool

Use this tool to compact adjacent complete supported terminal-style records after validated normalized style comparison; explicit text only, no escape scanning or terminal rendering.

How to use the tool and how it works

  1. Enter recordsJson using the field definitions below. For JSON text, serialize the explicit records in the shown shape.
  2. Run the operation. Correct input errors before interpreting an output.
  3. Read result.runs. Use the ordering, boundary rules and absence conditions described below.

Validate the explicit style records, group adjacent equal styles, concatenate their text, and return half-open source-record spans.2

Input fieldMeaning and unitsAccepted input
recordsJsonJSON text encoding array of {style: {bold: boolean, faint: boolean, italic: boolean, underline: boolean, inverse: boolean, strike: boolean, foreground: string, background: string}, text: 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.

json
{
  "recordsJson": [
    {
      "style": {
        "bold": false,
        "faint": false,
        "italic": false,
        "underline": false,
        "inverse": false,
        "strike": false,
        "foreground": "default",
        "background": "default"
      },
      "text": "a"
    },
    {
      "style": {
        "bold": false,
        "faint": false,
        "italic": false,
        "underline": false,
        "inverse": false,
        "strike": false,
        "foreground": "default",
        "background": "default"
      },
      "text": "b"
    }
  ]
}
Output fieldInterpretation
resultObject containing the named fields below.
result.runsAdjacent equal-style runs with source-record spans and concatenated text.
json
{
  "input": {
    "recordsJson": "[{\"style\": {\"bold\": false, \"faint\": false, \"italic\": false, \"underline\": false, \"inverse\": false, \"strike\": false, \"foreground\": \"default\", \"background\": \"default\"}, \"text\": \"a\"}, {\"style\": {\"bold\": false, \"faint\": false, \"italic\": false, \"underline\": false, \"inverse\": false, \"strike\": false, \"foreground\": \"default\", \"background\": \"default\"}, \"text\": \"b\"}]"
  },
  "output": {
    "result": {
      "runs": [
        {
          "start": 0,
          "end": 2,
          "style": {
            "bold": false,
            "faint": false,
            "italic": false,
            "underline": false,
            "inverse": false,
            "strike": false,
            "foreground": "default",
            "background": "default"
          },
          "text": "ab"
        }
      ]
    }
  }
}

Limitations and assumptions

  • Only adjacent equal normalized records merge; nonadjacent matching styles remain separate.
  • 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 Style Record Run Compactor — 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.