Cursor Pattern Detection
MonoTerm uses cursor visibility changes as frame boundaries - a universal pattern that works with all TUI applications.The Problem with BSU/ESU Adoption
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ BSU/ESU MODE 2026: ADOPTION REALITY │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ BSU/ESU is technically superior for atomic rendering. │
│ However, real-world adoption tells a different story. │
│ │
│ ┌──────────────────────────────────────────────────────────────────┐│
│ │ ││
│ │ AI CLI Tools Analyzed: 6 ││
│ │ Using BSU/ESU Natively: 1 (17%) <── Codex CLI ││
│ │ Using BSU/ESU Conditionally: 1 (17%) <── Claude ││
│ │ Using Cursor Pattern Only: 4 (66%) ││
│ │ ││
│ │ Result: Relying on BSU/ESU alone would miss 66% of AI CLIs ││
│ │ ││
│ └──────────────────────────────────────────────────────────────────┘│
│ │
│ Why is BSU/ESU rare? │
│ ──────────────────── │
│ 1. Terminal compatibility concerns (not all terminals support it) │
│ 2. TUI frameworks don't emit it by default │
│ 3. Cursor pattern is "good enough" for most use cases │
│ 4. Developers don't know about it │
│ │
└───────────────────────────────────────────────────────────────────────┘
DECTCEM: The Universal Standard
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ DECTCEM: DEC TEXT CURSOR ENABLE MODE │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ Mode ?25 controls cursor visibility. │
│ Part of VT220 standard (1983) - universally supported. │
│ │
│ │
│ Cursor Hide │
│ ═══════════ │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ ESC [ ? 2 5 l │ │
│ │ │ │
│ │ Meaning: "Hide the cursor" │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ │
│ Cursor Show │
│ ═══════════ │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ ESC [ ? 2 5 h │ │
│ │ │ │
│ │ Meaning: "Show the cursor" │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
└───────────────────────────────────────────────────────────────────────┘
Why Cursor Pattern Works as Frame Boundary
TUI frameworks hide the cursor during rendering to prevent visual artifacts. This creates natural frame boundaries.Copy
┌───────────────────────────────────────────────────────────────────────┐
│ CURSOR PATTERN AS IMPLICIT FRAME MARKER │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ Time ────────────────────────────────────────────────────────────→ │
│ │
│ ?25l Content Updates ?25h │
│ │ │ │
│ │ ┌───────────────────────────────────────┐ │ │
│ │ │ │ │ │
│ │ │ Frame Content │ │ │
│ │ │ (multiple write operations) │ │ │
│ │ │ │ │ │
│ │ └───────────────────────────────────────┘ │ │
│ │ │ │
│ Hide Show │
│ Cursor Cursor │
│ = = │
│ Frame Frame │
│ Start End │
│ │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ The cursor hide/show pattern aligns with rendering cycles. │
│ When cursor is hidden, the application is mid-render. │
│ When cursor is shown, the frame is complete. │
│ │
└───────────────────────────────────────────────────────────────────────┘
BSU/ESU vs Cursor Pattern Comparison
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ SEQUENCE COMPARISON │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┬────────────────────┬───────────────────────────┐│
│ │ Attribute │ BSU/ESU (2026) │ Cursor (?25) ││
│ ├─────────────────┼────────────────────┼───────────────────────────┤│
│ │ Purpose │ Explicit sync │ Cursor visibility ││
│ │ Introduced │ ~2019 (Kitty) │ 1983 (VT220) ││
│ │ Terminal │ Modern only │ Universal ││
│ │ Framework use │ Rarely │ Always ││
│ │ AI CLI usage │ 17% │ 100% ││
│ └─────────────────┴────────────────────┴───────────────────────────┘│
│ │
│ Key insight: │
│ Cursor pattern provides same frame boundary information │
│ with universal compatibility. │
│ │
└───────────────────────────────────────────────────────────────────────┘
MonoTerm Detection Strategy
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ DUAL DETECTION: BSU/ESU + CURSOR PATTERN │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ MonoTerm uses a priority-based detection system: │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Incoming PTY Data │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ ┌────────────────────┐ │ │
│ │ │ Check for BSU/ESU │───── Found? ────→ Use BSU/ESU │ │
│ │ │ (Mode 2026) │ (Priority 1) │ │
│ │ └─────────┬──────────┘ │ │
│ │ │ Not found │ │
│ │ ▼ │ │
│ │ ┌────────────────────┐ │ │
│ │ │ Check for Cursor │───── Found? ────→ Use as pseudo-BSU │ │
│ │ │ (Mode ?25) │ (Priority 2) │ │
│ │ └─────────┬──────────┘ │ │
│ │ │ Not found │ │
│ │ ▼ │ │
│ │ ┌────────────────────┐ │ │
│ │ │ Pass through │ │ │
│ │ │ (no atomic frame) │ │ │
│ │ └────────────────────┘ │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ Priority Rule: │
│ - If BSU/ESU active, cursor pattern ignored (nested frames) │
│ - If only cursor pattern present, treat as pseudo-BSU/ESU │
│ - If neither present, no atomic buffering │
│ │
└───────────────────────────────────────────────────────────────────────┘
State Machine
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ ATOMIC FRAME STATE MACHINE │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ │ │
│ ▼ │ │
│ ┌──────────────────┐ │ │
│ │ │ │ │
│ │ IDLE │←──────── ESU or ?25h ───────────┘ │
│ │ │ │
│ └────────┬─────────┘ │
│ │ │
│ │ BSU or ?25l │
│ ▼ │
│ ┌──────────────────┐ │
│ │ │ │
│ │ BUFFERING │─────── Buffer all content ───────┐ │
│ │ │ │ │
│ └──────────────────┘ │ │
│ │ │
│ On ESU or ?25h: │ │
│ ─────────────── │ │
│ 1. Flush all buffered data │ │
│ 2. Reset to IDLE │ │
│ 3. Emit complete frame ←───────────────────────────────┘ │
│ │
│ │
│ Buffer behavior: │
│ ──────────────── │
│ - IDLE: Data passes through immediately │
│ - BUFFERING: Data accumulates until frame end │
│ - Frame end: Atomic flush, single render cycle │
│ │
│ Timeout safety: │
│ If cursor remains hidden > 8ms, force flush to prevent stalls │
│ │
└───────────────────────────────────────────────────────────────────────┘
AI CLI Coverage Statistics
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ AI CLI COMPATIBILITY WITH EACH DETECTION METHOD │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ BSU/ESU Only: │
│ ───────────── │
│ │
│ Claude Code [ ] Conditional │
│ Gemini CLI [ ] No │
│ Aider [ ] No │
│ Open Interpreter [ ] No │
│ Codex CLI [═══════════════════] Yes (native) │
│ Kiro CLI [ ] No │
│ │
│ Coverage: 1/6 (17%) native │
│ │
│ │
│ Cursor Pattern (Pseudo-BSU/ESU): │
│ ──────────────────────────────── │
│ │
│ Claude Code [═══════════════════] Yes (via Ink) │
│ Gemini CLI [═══════════════════] Yes (via Ink fork) │
│ Aider [═══════════════════] Yes (via Rich) │
│ Open Interpreter [═══════════════════] Yes (via Rich) │
│ Codex CLI [═══════════════════] Yes (via Ratatui) │
│ Kiro CLI [═══════════════════] Yes (via Crossterm) │
│ │
│ Coverage: 6/6 (100%) │
│ │
│ │
│ Combined (BSU/ESU + Cursor): │
│ ──────────────────────────── │
│ │
│ All AI CLIs [═══════════════════] 100% coverage │
│ │
└───────────────────────────────────────────────────────────────────────┘
Implementation Notes
Copy
┌───────────────────────────────────────────────────────────────────────┐
│ PSEUDO-BSU/ESU IMPLEMENTATION CONSIDERATIONS │
├───────────────────────────────────────────────────────────────────────┤
│ │
│ 1. Nesting │
│ ────────── │
│ BSU/ESU can nest (spec allows multiple levels). │
│ Cursor pattern cannot nest (binary state). │
│ │
│ If BSU/ESU active: │
│ -> Cursor hide/show becomes regular cursor control │
│ -> Does not affect frame boundaries │
│ │
│ 2. Timeouts │
│ ────────── │
│ Both have safety timeouts to prevent indefinite buffering. │
│ - Cursor hide: 8ms │
│ - BSU/ESU: 16ms │
│ │
│ 3. Alternate Buffer │
│ ────────────────── │
│ Alternate screen often paired with cursor hide. │
│ Treat separately - alt buffer is screen switch, not frame boundary. │
│ │
│ 4. Pass-through │
│ ─────────────── │
│ BSU/ESU: Strip from output (terminal handled internally) │
│ Cursor: Pass through (application expects cursor state change) │
│ │
└───────────────────────────────────────────────────────────────────────┘
Summary
Copy
╔═════════════════════════════════════════════════════════════════════╗
║ ║
║ CURSOR PATTERN AS PSEUDO-BSU/ESU ║
║ ║
║ ┌───────────────────────────────────────────────────────────────┐║
║ │ │║
║ │ Problem: BSU/ESU adoption is only 17% │║
║ │ Solution: Use cursor hide/show as fallback frame boundary │║
║ │ Result: 100% AI CLI compatibility │║
║ │ │║
║ └───────────────────────────────────────────────────────────────┘║
║ ║
║ Detection priority: ║
║ 1. BSU/ESU (Mode 2026) - explicit, preferred ║
║ 2. Cursor (Mode ?25) - implicit, universal ║
║ ║
║ Key insight: ║
║ TUI frameworks emit cursor hide/show during render cycles. ║
║ This natural behavior provides frame boundaries automatically. ║
║ ║
╚═════════════════════════════════════════════════════════════════════╝
MonoTerm: Universal Atomic Rendering