On this page

ADR-0302: Automated TUI Geometry, Contrast, Cluster & Spin-Loop Linter (tui_lint)

Context

Terminal UIs fail in subtle ways across real user environments: low-contrast color pairings that pass on dark themes but fail WCAG AA on light backgrounds, CJK/wide-character grapheme clusters clipped or split at right viewport edges, overlapping non-modal sibling widgets, off-screen focused controls, clipped approval modals on narrow panes, and leaked timers or animation ticks that keep waking the event loop (wait_ms != -1) while rendered screen cells never change.

Manual visual inspection does not scale across viewport sizes, cluster policies, and dark/light palettes, and cannot catch idle CPU spin-loops reliably. Following ADR-0291 ("Freeze Rust, Grow in Tenon"), we want a pure, deterministic, zero-capability Tenon plugin that audits any tui.runtime.App or tui.types.Screen in-memory in milliseconds with identical behavior on both native C and tenon interp backends.

Decision

  1. New Pure Library Plugin plugins/tui_lint/ (capabilities = [])

    • contrast.tn (WCAG Contrast Audit):
      • Implements exact sRGB linearization (via pure-f64 Newton iteration for x2.4 with zero external math dependency) and WCAG 2.1 relative luminance and contrast ratio calculation.
      • Resolves tui.types.Color values (0 default terminal fg/bg against dark_palette() / light_palette() or Caps.background, 0x02000000 24-bit RGB, and 0x01000000 256-color indexed palette matching tui.present), plus SGR 7 reverse video (attrs & 16).
      • Audits non-decorative text spans (skipping whitespace and Unicode box-drawing/block elements U+2500..U+259F) against WCAG AA thresholds (>= 4.5 normal text, >= 3.0 bold/UI text).
    • geometry.tn (Geometry & Cluster Audit):
      • Accepts an optional vec<LintRect> ({ id, role, rect, modal, focused }) designed to pair directly with tui.a11y node rects after Wave 2 merge, with automatic fallback checks against screen.hits, screen.focus_order, and screen.modal.
      • Flags cursor_oob, row_overflow, cluster_clip (wide/CJK graphemes straddling the right screen edge), cluster_width_mismatch (declared span_cells disagreeing with display_width_policy), rect_overlap (overlapping non-modal siblings), focus_offscreen, and modal_clipped (clipped approval modals/dialogs).
    • spin.tn (Idle-Discipline / Spin-Loop Audit):
      • Runs tui.runtime.start + tick in-memory, stepping virtual Input.Clock forward up to 10,000 ms with zero user input.
      • Flags idle_spin_loop if wait_ms != -1 persists across repeated static-screen wakeups or reaches the horizon with unchanged rendered cells, while permitting both cleanly idle apps (wait_ms == -1) and active animations whose rendered cells genuinely change.
    • lib.tn (Matrix Runner & Structured JSON Reporting):
      • Provides audit_app, audit_app_with, and audit_screen across the standard 12-cell matrix [80x24, 120x40, 48x16] x [cluster=true, false] x [dark, light].
      • Serializes LintReport and Finding to json.lib.Value (report_to_value) and canonical JSON strings (report_to_json).
  2. DevTools Integration (plugins/tui_devtools/)

    • Adds tui_lint as a pure path dependency and exports LintSummary, lint_summary, lint_summary_line, lint_overlay, and overlay_with_lint so live TUI devtools overlays can display and export lint counts without modifying existing Counters / overlay callers.

Consequences