How Does Ghostty Work?

Published on

Ghostty is a great piece of software and I’d like to extend it to work better with my workflow. The problem is: I don’t know how Ghostty works. I don’t know how terminals work, how graphics programming works, how macOS and Linux desktop software works, and I don’t even know Zig. In this article, and perhaps others, I will document as much of this process as I can. I hope that this information is useful to others, and useful to my future self.

I will populate a to-do list with questions and actions, and show my working as I figure things out.

Learn Zig

Zig’s main website is https://ziglang.org. The Learn page lists not too many resources, so I will:

Which resources look useful?

Reference documentation is going to be vital. There are sections for Unstable (master) and Latest Stable (0.14.0). The choice is trivial because Ghostty’s flake.nix explicitly specifies Zig 0.14.0.

After opening everything else on the page except for the Relevant videos and blog posts (which seem rather irrelevant to me), here are my picks roughly in reading order:

Read Ziglings

This needs Zig 0.15.0. nix search nixpkgs zig only lists Zig 0.14.0. Someone tried to add a Nix flake to Ziglings, which was rejected but a comment suggests nix shell 'github:mitchellh/zig-overlay#master' as a workaround. Running that command and zig build in a local clone of the repo confirms this.

Time passes…

This was very enjoyable. Noteworthy discoveries: