Loom

A blog engine that just works. One binary, no setup, no dependencies.

Posts tagged “c++23” (13)

Putting It All Together — The Full PipelineMar 25 27.6K

Twelve posts of theory. Now we build. A complete, compilable, interactive terminal renderer — style interning, 8-byte cells, cell-level diffing, transition cache, synchronized output, threaded compositor. Copy it. Compile it. Resize your terminal. Watch zero flicker.

--c++23 --full-pipeline --demo --terminal-rendering --compositor --double-buffering --claude-code
Thread Safety — The CompositorMar 23 8.4K

The spinner thread and the main thread both want stdout. They can't have it. The Compositor is the bouncer: one lock, one writer, zero corruption. Plus the self-pipe trick, mutable regions, and why the mutex must cover the write() syscall.

--c++23 --compositor --mutex --thread-safety --signal-handling --self-pipe --claude-code
Double Buffering and Frame LifecycleMar 21 8.4K

Two buffers. Swap every frame. Clear, render, replay, diff, emit, swap. The complete lifecycle of a single frame, from event trigger to terminal update, in ~230 microseconds.

--c++23 --double-buffering --frame-lifecycle --synchronized-output --event-driven --claude-code
Hardware Scroll — Moving Rows Without RewritingMar 19 9.6K

The terminal can shift rows for you. You just have to ask nicely with CSI sequences, and then lie to your own diff engine about what the previous frame looked like. Result: 99% reduction in scroll I/O.

--c++23 --hardware-scroll --csi-sequences --scroll-region --memmove --terminal-rendering --claude-code
Style Transitions — The Transition CacheMar 17 9.6K

The single highest-leverage optimization in the entire pipeline. Computing the minimal ANSI to go from style A to style B, caching it forever, and never computing it again. 30-50% reduction in terminal output with one hash map.

--c++23 --style-transition --ansi-sgr --cache --optimization --terminal-rendering --claude-code
The Diff Engine — Only Paint What ChangedMar 15 10.8K

The heart of the renderer: compare two screen buffers cell by cell, emit the minimal ANSI to transform one into the other. Every optimization upstream exists to make this loop faster. Every optimization here directly reduces bytes to stdout.

--c++23 --diff-engine --ansi-escape --cursor-optimization --damage-rect --claude-code
The Render Tree Walk — From Layout to CellsMar 13 10.8K

The renderNode function is the most complex piece in the pipeline. It walks the component tree, decides what to re-render and what to skip, and orchestrates the entire frame. I extracted it from minified JavaScript, and the architecture is beautiful.

--c++23 --render-tree --yoga-layout --blit --dirty-flag --component-tree --claude-code
The Output Builder — Recording Before RenderingMar 11 10.8K

Claude Code doesn't render directly. It records what it wants to do, then replays the recording. This decoupling is what makes blit, clip, and scroll optimizations possible — and it's the reason 95% of the screen costs zero work per frame.

--c++23 --output-builder --variant --blit-optimization --damage-tracking --claude-code
Interning Pools — Strings Are Integers NowMar 09 12.0K

The moment you intern a style, comparison becomes integer equality. The moment you cache the transition between two styles, rendering becomes a hash table lookup. This is where Claude Code's renderer goes from fast to unreasonably fast.

--c++23 --interning --style-pool --transition-cache --constexpr --hash-map --claude-code
Cell Packing — Fitting a Universe into 8 BytesMar 07 8.4K

How do you fit a character, a style, a width, and type safety into exactly 8 bytes? Claude Code uses bitfield surgery. We use phantom-tagged IDs and static_assert. Both compile to one cmp instruction.

--c++23 --bit-packing --phantom-types --static-assert --memory-layout --claude-code
The Screen Buffer — A 2D Cell GridMar 05 9.6K

Every terminal UI, no matter how complex, reduces to filling a 2D grid of cells and diffing it against the previous frame. Claude Code uses a dual-view memory trick to make this fast. In C++, we don't need the trick.

--c++23 --terminal-rendering --screen-buffer --memory-layout --simd --claude-code
How I Ported Claude Code's Rendering Engine to Modern C++Mar 03 6.0K

I decompiled Claude Code's binary, reverse-engineered its terminal rendering pipeline, and rebuilt the whole thing in C++23. This is the story of what I found inside — and how to build a flicker-free, 60fps terminal UI from scratch.

--c++23 --terminal-rendering --reverse-engineering --tui --claude-code --ansi
The Problem — Why Terminals Are BrokenMar 03 7.2K

Two threads. One stdout. Total corruption. This is the bug that sent me reverse-engineering Claude Code's binary — and the fundamental reason every serious TUI needs a rendering engine.

--c++23 --terminal --tui --ansi-escape --race-condition --claude-code