I accidentally wrote a 100MB autoclicker
I love ghostty so much.
It's fast, it looks fantastic, tmux feels just right when you do fiddly stuff like resize panes, it gets out of my way.
I also love WSL2. Yeah yeah, I know what you're gonna say, Microsoft is an awful company and Windows sucks. But WSL2 gives me all the power of Linux, all the compatibility of Windows, and that's a compelling offering.
(by the way, can we agree to pronounce WSL "weasel" and not "double-view-ess-ell"? Unless, of course, you're one of those absolute sociopaths who says "ess-queue-ell" instead of "sequel"...
)
Sadly, there is no official ghostty support for Windows.
So I've tried running Windows Terminal, WezTerm, Alacritty, Hyper, Rio, and about a dozen others. It's miserable. They all fuck up something fundamental that ghostty gets right. They suck at tmux, they eat up all my memory, they're not themeable enough, too buggy, too slow..
But some nice people are working on it - There's a big Windows support thread that started in 2023 as issue #437, and it is slowly moving in the right direction (special thanks to deblasis).. but I need it now!
So I went fork hunting.
- Liamsmith86/ghostty-windows literally warns you that it is "AI SLOP" right in the README, so that's a non-starter. Love the honesty, though.
- Thr45hx/ghostty-windows says in the readme that they are "not a coder, just stubborn enough to bruteforce it". Naw.
- deblasis/wintty looks like it's heading towards a bright future, this is the one I'd bet on for the long play, but it's not done yet.
- amanthanvi/winghostty is not as full-blooded a solution as the deblasis approach, but it's more done, and I just need something that runs tmux real well.
So I used amanthanvi's fork for a few days, and it was working pretty well!
...but then it froze.
I figured it had crashed, but then I realized it was just sleeping while waiting for input. Whenever I typed something into the window or even just moved the mouse over the window, it would paint updates and catch up, otherwise it would stop painting after a few seconds.
First I looked online to see if I could fix this, maybe I could set a configuration option or something? Maybe there was an issue in the git repo with some solutions? But after five minutes of searching, I did what any self-respecting engineer would do: I just wrote a tiny script that would poke the winghostty window ten times per second. 
Since I'm a stupid idiot I figured powershell might be a good choice for the script that pokes a windows process, since powershell lives deep within the putrid guts of windows, right? But then I looked at its memory consumption:
102.4MB
fuck right off.
The powershell script itself was tiny. I did not write 100MB of logic, but for some god damn reason, the script was wearing a 100MB pair of pants.
My script was basically:
while ($true) {
# find winghostty windows
# call InvalidateRect
Start-Sleep -Milliseconds 100
}But see, because powershell runs as a .NET application, starting any powershell script means you're loading the host, the .NET runtime, the garbage collector, reflection, assemblies, type metadata, providers, module machinery, formatting, object pipeline stuff, and a pile of other things that make it arguably useful.
It's as if I was renting an orchestra to play a doorbell.
So I rewrote it in Zig
ever heard of Zig? It's suuuper fast and lean. You know what's written in Zig? motherfuckin' ghostty, terminal software extraordinaire. So I figured, it would be poetic to write the little pokey-script piece of shit in the same language as the thing it was poking, yeah?
So I wrote a 100 line thing in Zig that imports some windows stuff, finds and pokes the window, and then sleeps a bit (repo can be found here). Then I built it using this command:
zig build-exe main.zig -target x86_64-windows-gnu -O ReleaseSmall \
-fsingle-threaded --subsystem windowsThe magic here is ReleaseSmall and -fsingle-threaded, which are two pieces of arcane warlockery that hyper-optimize the executable by getting rid of thread safety and other shit I didn't need.
The resulting executable has a total size of
holy mother of batman
4096 bytes (!!!)
But how?
Zig's philosophy is basically, look, this car only has to drive down to the bodega to buy some cigarettes and divorce your mom, it's fifteen meters, do we really need seatbelts, a glove compartment, passenger seats, or the bit that goes honk? (sorry, I don't know how cars work)
you know what, just get rid of everything except one seat, a steering wheel and two tyres.
Congratulations, you're riding a bike. Which is pretty sweet if your problem is bike-sized.
COMMENTS
nobody's said anything yet. break the seal.
0 / 2000
loading challenge...