ghostling-libghostty-terminal

Build minimal terminal emulators using the libghostty-vt C API with Raylib for windowing and rendering

By reason-machines · 1,104 installs

npx skills add reason-machines/trending-skills --skill ghostling-libghostty-terminal

Source repository · Upstream listing

Ghostling — libghostty Terminal Emulator Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection. Ghostling is a minimal viable terminal emulator built on libghostty vt , the embeddable C library extracted from [Ghostty](https://ghostty.org). It uses Raylib for windowing/rendering and lives in a single C file. The project demonstrates how to wire libghostty vt's VT parsing, terminal state, and render state API to any 2D or GPU renderer. What libghostty vt Provides VT sequence parsing (SIMD optimized) Terminal state: cursor, styles, text reflow, scrollback Render state management (what cells changed and how to draw them) Unicode / multi codepoint grapheme handling Kitty keyboard protocol, mouse tracking, focus reporting Zero dependencies (not even libc) — WASM compatible libghostty vt does NOT provide: windowing, rendering, PTY management, tabs, splits, or configuration. Requirements Tool Version CMake 3.19+ Ninja any C compiler clang/gcc Zig 0.15.x (on PATH) macOS Xcode CLT or Xcode Build & Run After first configure, only the build step is needed: Warning: Debug builds are very slow due to Ghostty's safety/correctness assertions. Always benchmark with Release builds. Project Structure Core libghostty vt API Patterns All implementation lives in main.c . Below are the key patterns extracted from it. 1. Initialize the Terminal 2. Write Data from PTY into the Terminal 3. Send Keyboard Input 4. Send Mouse Events 5. Resize the Terminal 6. Render: Walk the Render State The render state API tells you exactly which cells changed and how to draw them — no need to redraw everything every frame. 7. Scrollback 8. Cursor Position 9. Cleanup PTY Setup (POSIX) libghostty vt has no PTY management — you own this: CMakeLists.txt Pattern The project fetches libghostty vt automatically via CMake FetchContent: Key Enums & Constants Common Patterns Non blocking PTY Read Loop Raylib Key → ghostty key t Mapping Scrollbar Rendering Troubleshooting Problem Fix Build fails: zig not found Install Zig 0.15.x and ensure it's on $PATH Debug build extremely slow Use Release: cmake B build G Ninja DCMAKE BUILD TYPE=Release Terminal renders garbage Verify you're calling ghostty render state begin before iterating cells and ghostty render state end after Child process not getting resize Call ioctl(pty fd, TIOCSWINSZ, &ws) AND kill(child pid, SIGWINCH) after ghostty terminal resize Kitty keyboard protocol broken Known upstream Raylib/GLFW limitation — libghostty vt supports it correctly but needs richer input events Colors look wrong Check cell.fg / cell.bg — libghostty vt resolves palette to RGB, use those values directly ghostty terminal write crashes Ensure buffer passed is valid and len 0 ; never pass NULL What libghostty vt Will NOT Do For You You must implement these yourself: PTY creation and process management Window creation and event loop Font loading and glyph rendering Clipboard read/write (OSC 52 bytes are provided, handling is yours) Tabs, splits, multiple windows Configuration UI API Reference Full libghostty vt C API docs: https://libghostty.tip.ghostty.org/group render.html