Authors need portable cursor stacking without SCO-specific CSI variants in typed builders.
Flow and algorithm
Platform spec article
Flow and algorithm
Spec standingStandard
-
Normative cursor save/restore uses DEC sequences, not SCO.
Context
Decision
Rule Detail Save/restore DEC ESC 7/ESC 8is the normative pairSCO CSI s/CSI uare not required in v1 typed buildersConsequences
Typed
Ansi.Cursorhelpers emit DEC only; rawCsimay still be used in tests.Verification anchors
AnsiEscapeTests.bd;ANSI.mdtables. -
Styled emission must respect ShouldEmitAnsi and non-TTY hosts.
Context
Programs must not leak escapes to pipes, log files, or NO_COLOR environments.
Decision
Rule Detail Gating User-visible styled output must pass Ansi.Escape.WhenEnabledTests Ungated Csiremains for golden testsConsequences
When
ShouldEmitAnsi()is false, gated builders return empty strings.Verification anchors
AnsiEscapeTests.bd; console capability integration. -
Truecolor sequences downgrade via EffectiveColorModel.
Context
Terminals differ in color depth; emitting unsupported
38;2breaks dumb hosts.Decision
Rule Detail Ladder truecolor → 256 → basic per EffectiveColorModelPolicy Callers do not pick per-sequence models manually Consequences
SGR builders consult capability probes before emitting RGB CSI.
Verification anchors
AnsiSgrGoldenTests.bd;CapabilitiesTests.bd. -
OSC payloads terminate with BEL, not ST.
Context
OSC framing varies across terminals; v1 picks one terminator for golden tests.
Decision
Rule Detail Terminator BEL ( 0x07) in v1ST ESCtermination is not requiredConsequences
OSC helpers emit BEL-terminated sequences only until a future ADR extends ST.
Verification anchors
AnsiEscapeTests.bd;Ansi.Oscsources.
- Contracts and edge cases MUST/SHOULD rules for escape emission and supported sequence subsets.
- Design model ESC/CSI/OSC taxonomy and normative control-character tables for terminal output.
- Examples Representative escape composition and gated emission patterns.
- Flow and algorithm How escape bytes are composed, gated, and written to stdout.
- Verification and traceability Golden tests and source anchors for ANSI escape framing.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
what-this-feature-specifies | yes | yes |
implementation-anchors | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Purpose
Section titled “Purpose”Describe how escape bytes are composed, gated by capabilities, and written to stdout.
Canonical references
Section titled “Canonical references”- Tables: design model
- Requirements: contracts and edge cases
- Write path: Console I/O streams / flow and algorithm
Detailed behavior
Section titled “Detailed behavior”Emission pipeline
Section titled “Emission pipeline”flowchart LR markup[Console.Format or Ansi builders] gate[Ansi.Escape.WhenEnabled] bytes[UTF-8 string] out[System.Output.Write / WriteLine] markup --> gate --> bytes --> out
- Compose — Fluent builders (
Cursor,Erase,Sgr) accumulate parameter strings;JoinArgsinserts;between SGR parameters without trailing separators. - Frame —
Csi/PrivateMode/DecSaveCursor/OscSequenceproduce raw escape strings (ungated). - Gate —
WhenEnabledreturns""or the sequence based onShouldEmitAnsi()(stdout TTY + color policy). - Deliver — Higher layers (
Console.FormatLine, controls renderers) pass the final string to Console I/O streams helpers.
SGR color downgrade algorithm
Section titled “SGR color downgrade algorithm”When SgrBuilder.FgRgb / BgRgb runs:
Capabilities.ProbeStdout()reads TTY and environment flags.EffectiveColorModelselects TrueColor, Indexed256, or Basic16 (or forces basic when color is stripped).- Parameter bytes are chosen:
- TrueColor →
38;2;r;g;b/48;2;r;g;b - Indexed256 →
38;5;n/48;5;nviaRgbTo256Index - Basic → nearest
30–37/40–47viaRgbToBasicForeground/RgbToBasicBackground
- TrueColor →
IntoPrefixcallsEmitCsi(openArgs, "m");ApplyToappends text andResetSuffix(ESC[0mgated).
Builder concatenation
Section titled “Builder concatenation”Ansi.Cursor.CursorBuilder appends fragments in call order, then IntoSequence applies a single gate at the end. Multiple CSI operations in one string are valid because terminals process them left-to-right.
Test-only ungated paths
Section titled “Test-only ungated paths”Verification
Section titled “Verification”CapabilitiesTests.bd asserts empty gated output when ANSI disabled; golden tests use ungated CsiSequence for framing only.
Related topics
Section titled “Related topics”- Examples
- Console controls — frame save/restore around render
Conformance tests call CsiSequence and PrivateMode directly to assert framing without depending on TTY state. Production markup must use EmitCsi or builders that call WhenEnabled.