Skip to main content

What is MonoTerm?

MonoTerm is a terminal rendering system that delivers complete frames - never partial garbage.

The Problem We Solved

Traditional terminals render whatever comes in, whenever it comes.
┌─────────────────────────────────────────────────────────────────┐
│  THE PROBLEM: UNCOORDINATED RENDERING                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Program writes:    "Hello"                                    │
│   Screen shows:      "Hel"       (partial, still writing)       │
│                                                                 │
│   Program writes:    "lo World"                                 │
│   Screen shows:      "Hello Wor" (still incomplete!)            │
│                                                                 │
│   Program writes:    "ld!"                                      │
│   Screen shows:      "Hello World!" (finally complete)          │
│                                                                 │
│   ───────────────────────────────────────────────────────────   │
│                                                                 │
│   User sees THREE screen updates for ONE logical update         │
│   Result: Flicker, tearing, visual artifacts                    │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

The MonoTerm Solution

MonoTerm waits for complete frames before rendering.
┌─────────────────────────────────────────────────────────────────┐
│  THE SOLUTION: FRAME-COORDINATED RENDERING                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Program writes:    [cursor hide] + "Hello World!" + [show]    │
│                              │                       │          │
│                              │  MonoTerm detects:    │          │
│                              │  "Frame boundary!"    │          │
│                              ▼                       ▼          │
│   Screen shows:      ──────(nothing)────────▶ "Hello World!"    │
│                                                                 │
│   ───────────────────────────────────────────────────────────   │
│                                                                 │
│   User sees ONE screen update for ONE logical update            │
│   Result: No flicker, no tearing, atomic frames                 │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

The 5-Tier Architecture

MonoTerm uses a 5-Tier Architecture - each tier has a single responsibility.
┌─────────────────────────────────────────────────────────────────┐
│  MONOTERM 5-TIER ARCHITECTURE                                   │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  TIER 1: PTY DAEMON                                             │
│  ───────────────────                                            │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Your Shell (bash, zsh, fish)                           │    │
│  │       │                                                 │    │
│  │       ▼                                                 │    │
│  │  Unix Socket per Session                                │    │
│  │  Raw bytes (no parsing here)                            │    │
│  └─────────────────────────────────────────────────────────┘    │
│                     │                                           │
│                     ▼                                           │
│  TIER 2: SESSION ACTOR                                          │
│  ─────────────────────                                          │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Pattern: Actor Model - Single Owner, NO LOCKS          │    │
│  │                                                         │    │
│  │  Commands via MPSC Channel:                             │    │
│  │    WriteToPty, ResizeSession, GridAck                   │    │
│  │    CreateSession, CloseSession, HandlePtyData           │    │
│  └─────────────────────────────────────────────────────────┘    │
│                     │                                           │
│                     ▼                                           │
│  TIER 3: ATOMIC STATE                                           │
│  ────────────────────                                           │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Frame boundary detection (BSU/ESU, cursor patterns)    │    │
│  │  Line comparison for minimal data transfer              │    │
│  │  ACK gate for flow control                              │    │
│  └─────────────────────────────────────────────────────────┘    │
│                     │                                           │
│                     ▼                                           │
│  TIER 4: CELL CONVERTER                                         │
│  ──────────────────────                                         │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Alacritty Cell → xterm.js format                       │    │
│  │  DiffHint: Full, Partial, ScrollOnly, None              │    │
│  └─────────────────────────────────────────────────────────┘    │
│                     │                                           │
│                     ▼                                           │
│  TIER 5: GRID BUFFER INJECTOR                                   │
│  ────────────────────────────                                   │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  Direct xterm.js internal manipulation                  │    │
│  │  WebGL Renderer                                         │    │
│  │       ▼                                                 │    │
│  │  YOUR SCREEN                                            │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Key Components

PTY Daemon (Rust)

Runs your shell as a completely separate process.
┌─────────────────────────────────────────────────────────────────┐
│  PTY DAEMON                                                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   You type:  ls -la                                             │
│       │                                                         │
│       ▼                                                         │
│   ┌─────────────┐                                               │
│   │ Your Shell  │  (bash, zsh, fish, etc.)                      │
│   └─────────────┘                                               │
│       │                                                         │
│       ▼                                                         │
│   Output: file listing with colors, formatting                  │
│                                                                 │
│   Benefit: Survives main app crash                              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

VTE Parser (Alacritty)

Interprets escape sequences using battle-tested code from Alacritty terminal.
┌─────────────────────────────────────────────────────────────────┐
│  VTE PARSER                                                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Input:  ESC[31mHelloESC[0m                                    │
│              │                                                  │
│              ▼                                                  │
│   Meaning: [red color] Hello [reset color]                      │
│              │                                                  │
│              ▼                                                  │
│   Grid:   Cell(H, red), Cell(e, red), Cell(l, red), ...         │
│                                                                 │
│   Benefit: Battle-tested parsing (Alacritty = production)       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Atomic Loop

Detects when a complete frame is ready.
┌─────────────────────────────────────────────────────────────────┐
│  ATOMIC LOOP                                                    │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Detection Methods:                                            │
│                                                                 │
│   1. Cursor Hide/Show (Ink Pattern)                             │
│      ┌─────────────────────────────────────────────┐            │
│      │ Cursor HIDE ── content ── Cursor SHOW       │            │
│      │     │                          │            │            │
│      │  "Drawing"              "Done drawing"      │            │
│      └─────────────────────────────────────────────┘            │
│                                                                 │
│   2. BSU/ESU (DECSET Mode 2026)                                 │
│      ┌─────────────────────────────────────────────┐            │
│      │ BSU ─────── content ─────── ESU             │            │
│      │  │                           │              │            │
│      │ "Begin"                   "End"             │            │
│      └─────────────────────────────────────────────┘            │
│                                                                 │
│   3. Implicit Sync (Timeout)                                    │
│      ┌─────────────────────────────────────────────┐            │
│      │ Clear screen ── wait 8ms ── assume done     │            │
│      └─────────────────────────────────────────────┘            │
│                                                                 │
│   Benefit: Works with existing programs (no changes needed)     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Smart Diff

Compares frames to minimize data transfer.
┌─────────────────────────────────────────────────────────────────┐
│  SMART DIFF                                                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Previous Frame          Current Frame                         │
│   ┌────────────┐          ┌────────────┐                        │
│   │ Line 1 ████│          │ Line 1 ████│  same                  │
│   │ Line 2 ████│          │ Line 2 ████│  same                  │
│   │ Line 3 ████│    vs    │ Line 3 ░░░░│  CHANGED!              │
│   │ Line 4 ████│          │ Line 4 ████│  same                  │
│   └────────────┘          └────────────┘                        │
│                                                                 │
│   Result: Only send Line 3                                      │
│           99.95% less data!                                     │
│                                                                 │
│   Benefit: Fast even with slow connections                      │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

ACK Gate

Prevents overwhelming the frontend with backpressure.
┌─────────────────────────────────────────────────────────────────┐
│  ACK GATE (Flow Control)                                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Without ACK (Traditional):                                    │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │  Backend: SEND SEND SEND SEND SEND SEND SEND...         │   │
│   │  Frontend: ──processing── can't keep up!                │   │
│   │  Result: Lag, frozen UI, dropped frames                 │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   With ACK (MonoTerm):                                          │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │  Backend: SEND ── wait ── SEND ── wait ── ...           │   │
│   │  Frontend: process → ACK → process → ACK → ...          │   │
│   │  Result: Smooth, no lag, no drops                       │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   Benefit: Frontend always in control                           │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Why “Atomic”?

┌─────────────────────────────────────────────────────────────────┐
│  ATOMIC = INDIVISIBLE                                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   In physics: An atom is the smallest unit of matter            │
│                                                                 │
│   In MonoTerm: A frame is the smallest unit of display          │
│                                                                 │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                                                         │   │
│   │     You see complete frames                             │   │
│   │     or nothing at all.                                  │   │
│   │                                                         │   │
│   │     Never partial garbage.                              │   │
│   │                                                         │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   This is the "Atomic UX" promise.                              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Performance

┌─────────────────────────────────────────────────────────────────┐
│  REAL-WORLD PERFORMANCE                                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Scenario: Normal typing                                       │
│   ─────────────────────────                                     │
│                                                                 │
│   Traditional Terminal:                                         │
│     Data per keystroke: 50,000 bytes (full screen redraw)       │
│                                                                 │
│   MonoTerm:                                                     │
│     Data per keystroke: 25 bytes (only cursor line)             │
│                                                                 │
│   Reduction: 99.95%                                             │
│                                                                 │
│   ───────────────────────────────────────────────────────────   │
│                                                                 │
│   Scenario: AI streaming (100 chars/sec)                        │
│   ─────────────────────────────────────                         │
│                                                                 │
│   Traditional Terminal:                                         │
│     May freeze or lag (rendering can't keep up)                 │
│                                                                 │
│   MonoTerm:                                                     │
│     Smooth streaming always (ACK gate prevents flooding)        │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Summary

┌─────────────────────────────────────────────────────────────────┐
│  MONOTERM IN ONE PICTURE                                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Shell Output                                                  │
│       │                                                         │
│       ▼                                                         │
│   ┌─────────┐    ┌─────────┐    ┌─────────┐    ┌─────────┐      │
│   │  PTY    │───▶│  VTE    │───▶│ Atomic  │───▶│  Smart  │      │
│   │ Daemon  │    │ Parser  │    │  Loop   │    │  Diff   │      │
│   └─────────┘    └─────────┘    └─────────┘    └─────────┘      │
│                                      │              │           │
│                              Wait for frame   Find changes      │
│                              boundaries                         │
│                                      │              │           │
│                                      ▼              ▼           │
│                               ┌─────────────────────────┐       │
│                               │       ACK Gate          │       │
│                               │   (Flow Control)        │       │
│                               └───────────┬─────────────┘       │
│                                           │                     │
│                                           ▼                     │
│                                    ┌─────────────┐              │
│                                    │   xterm.js  │              │
│                                    │   WebGL     │              │
│                                    └─────────────┘              │
│                                           │                     │
│                                           ▼                     │
│                                      Your Eyes                  │
│                                                                 │
│   Technologies: Rust, Alacritty, Tauri, MPSC, Unix Socket       │
│   Result: Smooth, atomic frames with minimal data transfer      │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘