Skip to content

[Research] Lightweight TUI replacement - Raw ANSI vs React/Ink #27

@randomm

Description

@randomm

Problem

Current binary is ~95MB and feels sluggish. The TUI uses Ink (React-based terminal UI) which adds significant overhead.

Research Direction

Explore replacing the React/Ink TUI with a lightweight raw ANSI implementation.

Proposed Architecture

┌─────────────────────────────────────────────────────┐
│ claude-sonnet-4-20250514 · build                    │ ← sticky header
├─────────────────────────────────────────────────────┤
│                                                     │
│ ... chat content with syntax highlighting ...       │ ← scrollable
│                                                     │
├─────────────────────────────────────────────────────┤
│ ⏳ explore (12s) │ ⏳ websearch (3s) │ ✓ grep       │ ← sticky jobs bar
├─────────────────────────────────────────────────────┤
│ > _                                                 │ ← input
└─────────────────────────────────────────────────────┘

Library Comparison

Library Sticky regions Syntax HL Size Speed
terminal-kit ✓ screenBuffer External ~150KB Fast
blessed ✓ boxes External ~200KB Medium
Raw ANSI Manual cursor External 0 ⚡ Fastest
ink (current) ✓ (React) External ~200KB+ Slower

Recommendation: Raw ANSI + cli-highlight

  • Zero framework overhead
  • ~550 lines total code
  • Dependencies: picocolors (~5KB), cli-highlight (~30KB)

Core Components Needed

  1. terminal.ts (~150 lines) - Region management, cursor control
  2. main.ts (~300 lines) - Event loop, commands
  3. format.ts (~100 lines) - Markdown, code highlighting

Key Features

  • Sticky header (model/agent)
  • Scrollable chat region
  • Sticky jobs bar with live timers
  • Input line with cursor

Integration with Background Tasks

Jobs bar would show running background tasks with elapsed time, updating every second.

Research Questions

  1. What's the actual size breakdown of current binary? (Bun runtime vs app code vs deps)
  2. Can we achieve <20MB binary with raw ANSI approach?
  3. What TUI features would we lose? Are they essential?
  4. How much of packages/opencode/src/cli/cmd/tui/ can be deleted?

Out of Scope (for now)

  • Mouse support
  • Complex layouts
  • Rich widgets

Acceptance Criteria

  • Research current binary size breakdown
  • Prototype raw ANSI terminal abstraction
  • Measure performance difference
  • Document trade-offs
  • Decision: migrate or keep Ink

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions