Authors need portable cursor stacking without SCO-specific CSI variants in typed builders.
Contracts and edge cases
Platform spec article
Contracts and edge cases
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”State MUST/SHOULD rules for escape framing, capability gating, and the v1 conformance-tested CSI subset.
Canonical references
Section titled “Canonical references”- Feature hub: ANSI escape model
- Sequence tables: design model and repository
ANSI.md - Color downgrade: Console capabilities
Detailed behavior
Section titled “Detailed behavior”Normative requirements
Section titled “Normative requirements”| ID | Requirement |
|---|---|
| ANSI-001 | Ansi.Escape.Esc() must return exactly one U+001B code unit. |
| ANSI-002 | Csi(body, finalByte) must produce ESC[ + body + finalByte with no capability filtering (test and composition primitive). |
| ANSI-003 | EmitCsi, EmitOsc, EmitDec, and builders whose IntoSequence calls WhenEnabled must return "" when Console.Capabilities.ShouldEmitAnsi() is false. |
| ANSI-004 | PrivateMode(mode, enable) must encode ESC[?{mode}h or ESC[?{mode}l. |
| ANSI-005 | DecSaveCursor / DecRestoreCursor must emit ESC 7 and ESC 8 respectively (single-byte suffix, no bracket). |
| ANSI-006 | OscSequence(payload) must terminate with BEL (0x07). |
| ANSI-007 | SgrBuilder RGB helpers must downgrade per EffectiveColorModel before calling EmitCsi (see Console capabilities). |
| ANSI-008 | Golden tests listed in verification and traceability must match byte-for-byte output when emission is enabled. |
Conformance-tested CSI final bytes (v1)
Section titled “Conformance-tested CSI final bytes (v1)”| Final | Builder surface | Example |
|---|---|---|
m | Ansi.Sgr, Ansi.StyleChain | ESC[1;31m |
A–G, H, f | Ansi.Cursor | ESC[2J via Ansi.Erase uses J/K |
J, K | Ansi.Erase | ESC[2J, ESC[2K |
h, l | Ansi.Escape.PrivateMode, Ansi.Screen | ESC[?1049h |
Sequences present in ANSI.md but without a corelib builder or golden test are informative until added to this table.
Edge cases
Section titled “Edge cases”- Piped stdout: When stdout is not a TTY and
FORCE_COLORis unset, styled helpers must emit no escapes (ANSI-003); plainSystem.Output.Writestill writes bytes. - Partial terminal support: Terminals may ignore italic, blink, or truecolor; downgrade reduces garbled output but cannot guarantee visual fidelity.
- Multiplexers (
tmux,screen): Alternate-buffer and private-mode sequences may behave differently; corelib does not special-case multiplexers in v1. - Keyboard redefinition (
ESC[{code};{string}p): Not implemented; documented inANSI.mdfor historical completeness only. - Erase without cursor move: After
ESC[2K, callers should emit\rif the cursor must sit at column 1 (see design model).
Non-goals (v1)
Section titled “Non-goals (v1)”Verification
Section titled “Verification”Each ANSI-* row maps to AnsiEscapeTests.bd / AnsiSgrGoldenTests.bd or capability tests — verification and traceability.
Related topics
Section titled “Related topics”-
Console markup format — must use builders, not raw ESC in markup
-
DCS string handling
-
Full xterm private-mode catalog
-
Host-specific WIN32 console APIs beyond
Platform.*extern stubs