Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Flow and algorithm

Platform spec article

Flow and algorithm

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

Describe how escape bytes are composed, gated by capabilities, and written to stdout.

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
  1. Compose — Fluent builders (Cursor, Erase, Sgr) accumulate parameter strings; JoinArgs inserts ; between SGR parameters without trailing separators.
  2. FrameCsi / PrivateMode / DecSaveCursor / OscSequence produce raw escape strings (ungated).
  3. GateWhenEnabled returns "" or the sequence based on ShouldEmitAnsi() (stdout TTY + color policy).
  4. Deliver — Higher layers (Console.FormatLine, controls renderers) pass the final string to Console I/O streams helpers.

When SgrBuilder.FgRgb / BgRgb runs:

  1. Capabilities.ProbeStdout() reads TTY and environment flags.
  2. EffectiveColorModel selects TrueColor, Indexed256, or Basic16 (or forces basic when color is stripped).
  3. Parameter bytes are chosen:
    • TrueColor → 38;2;r;g;b / 48;2;r;g;b
    • Indexed256 → 38;5;n / 48;5;n via RgbTo256Index
    • Basic → nearest 30–37 / 40–47 via RgbToBasicForeground / RgbToBasicBackground
  4. IntoPrefix calls EmitCsi(openArgs, "m"); ApplyTo appends text and ResetSuffix (ESC[0m gated).

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.

CapabilitiesTests.bd asserts empty gated output when ANSI disabled; golden tests use ungated CsiSequence for framing only.

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.