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.
Zig’s main website is https://ziglang.org. The Learn page lists not too many resources, so I will:
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:
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:
const
applies to the contents of an array, so an array is not a boxed type."ha " ** 3
be equivalent to [_]u8{'h','a',' ',0} ** 3
or "ha \0ha \0ha "
? I suppose the fact that strings are null-terminated is represented in the type so that **
knows not to replicate the null terminator.switch
seems is equivalent to a series of if
statements checking for equality, which is not quite the same as in C. C switch
only works on integers. (I can’t verify this from the language reference).p.*.f
to access field f
within the referenced struct.