F
FrankenTUI
Technical Specification

Inside the
Machine.

A deep dive into the 16-byte cell architecture, Bayesian rendering strategies, and the zero-unsafe kernel that powers FrankenTUI.

Data Flow

The Render Cycle

Every frame follows a deterministic, 5-stage pipeline. Pure state transitions, no hidden I/O.

Event

Input capture

01

Update

State transition

02

View

Virtual buffer

03

Diff

Bayesian selection

04

Present

ANSI emission

05
Binary Purity

16-Byte Cell Model

The atom of FrankenTUI. Cache-aligned, SIMD-ready, and designed for extreme performance.

cell.rs
┌─────────────────────────────────────────────────────────────────┐
│                        Cell (16 bytes)                          │
├─────────────┬─────────────┬─────────────┬─────────────┬────────┤
│ CellContent │     fg      │     bg      │   attrs     │ link_id│
│  (4 bytes)  │ PackedRgba  │ PackedRgba  │  CellAttrs  │  (2B)  │
│  char/gid   │  (4 bytes)  │  (4 bytes)  │  (2 bytes)  │        │
└─────────────┴─────────────┴─────────────┴─────────────┴────────┘

Cache Optimal

4 cells fit perfectly in a 64-byte L1 cache line.

SIMD Ready

Single 128-bit instruction for full cell equality.

Zero Leak

RAII-backed grapheme cleanup prevents memory growth.

Intelligence

Monster Math

Algorithms borrowed from statistical machine learning, not hand-tuned heuristics.

Rendering

Bayesian Diff Strategy

Beta posterior over change rates adaptively selects between full diff, dirty-row, and full redraw strategies.

p ~ Beta(α, β)
ImpactAvoids slow strategies as workload shifts
Runtime

BOCPD Resize Coalescing

Bayesian Online Change-Point Detection detects regime transitions between steady typing and burst resizing.

P(r_t | x₁:t) with hazard H(r) = 1/λ
ImpactFewer redundant renders during window drag
Budget Control

E-Process Monitoring

Wealth-based sequential tests for anytime-valid statistical decisions. No peeking penalty.

W_t = W_{t-1}(1 + λ_t(X_t - μ₀))
ImpactSafe budget decisions at every frame
Alerting

Conformal Prediction

Distribution-free risk bounds that learn 'normal' from recent residuals.

q = Quantile_{⌈(1-α)(n+1)⌉}(R₁,...,Rₙ)
ImpactStable alert thresholds without tuning
Data Structures

Fenwick Tree

Binary Indexed Tree for O(log n) prefix sums in virtualized lists.

update: j += j & -j | query: j -= j & -j
ImpactO(log n) scroll positioning
Input

CUSUM Hover Stabilizer

Cumulative sum change-point detector suppresses mouse jitter at hover boundaries.

S_t = max(0, S_{t-1} + d_t - k)
ImpactStable hover targets without lag
Animation

Damped Spring Physics

Critically-damped harmonic oscillator for natural motion without overshoot.

x'' + c·x' + k(x - x*) = 0
ImpactSmooth, deterministic animation
Input Guard

Jain's Fairness Index

Scale-independent fairness metric prevents rendering from starving input processing.

F = (Σxᵢ)² / (n·Σxᵢ²)
ImpactResponsive UI under heavy render load
Rendering

Porter-Duff Compositing

Full alpha-blending pipeline with opacity stacks for translucent overlays and layered widgets.

C_out = C_src·α_src + C_dst·α_dst·(1-α_src)
ImpactTrue transparency without hacks
Diagnostics

VOI Telemetry

Value-of-Information analysis that tracks which diagnostic measurements actually improve decisions.

VOI = E[max(a,b)|X] - max(E[a],E[b])
ImpactSelf-tuning diagnostic overhead
Frame Timing

Exponential Moving Average

Smoothed frame-time estimation for adaptive budget allocation across render cycles.

EMA_t = α·x_t + (1-α)·EMA_{t-1}
ImpactStable frame budgets despite jitter
Visual Effects

Gray-Scott Reaction-Diffusion

PDE-based pattern generator for organic visual effects rendered entirely in terminal cells.

∂u/∂t = Dᵤ∇²u - uv² + F(1-u)
ImpactMathematical art in the terminal
Invariants

Architecture Rules

Core principles enforced at the type and crate level.

One-Writer Rule

All stdout goes through TerminalWriter. Single serialization point eliminates race conditions.

RAII Cleanup

State restored on drop—even on panic. Your terminal never stays broken.

Deterministic

Identical Model state + terminal size = bit-identical ANSI output. Always.

Zero Unsafe

#![forbid(unsafe_code)] across all core rendering and layout crates.

Ready to build?

Add FrankenTUI to your project and start building interfaces with correctness guarantees from day one.