You are browsing as a guest. Sign up (or log in) to start making projects!

12h 34m 59s logged

Loading Spinner and Splitting Up main.go

Thanks so much to everyone who took the time to comment, rate, and drop feedback on my latest ship. All of it was genuinely so helpful and I’ve been spending the last couple days fixing things up a bit. I totally forgot to devlog so I’m actually losing a couple hours since it’s been over ten hours since my last one :sob

A loading spinner while Hackatime fetches

One reviewer pointed out that hackfetch takes a couple of seconds when it’s pulling your Hackatime stats for the first time, and there was no signal that anything was happening. Now there is.

⠋ fetching Hackatime...

The spinner cycles through 10 braille frames and the whole line clears out the instant the fetch finishes. Same fetch, way less awkward pause.
Two small details that make it feel right:

  • It only shows when stderr is actually a terminal, so it doesn’t spam control codes into your log files if you redirect output.
  • It prints one frame immediately, so fast fetches still flash something instead of nothing.

hackfetch runs it around the API calls automatically. No config, no opt-in. It’s just there.

Splitting up main.go

Another reviewer said the 1.5k-line file was too much. They were completely right. hackfetch had grown into one giant main.go that held the logos, the color schemes, the Hackatime API client, the terminal render, the SVG exporter, the PNG rasterizer, everything.

Refactored today into files that each do one thing:

  • logos.go: the ASCII logos
  • colors.go: color schemes and the ANSI → hex table
  • config.go: reads ~/.wakatime.cfg
  • hackatime.go: the API client, caching, and language inference
  • sysinfo.go: OS, shell, editor, terminal
  • setup.go: the -setup flow
  • render.go: terminal render, watch loop, and layout
  • export.go: SVG, PNG, and JPG exporters
  • main.go: just flag parsing and the entry point (~100 lines instead of 1,600)

Same binary, same behavior, zero user-visible change. But next time I want to add a new logo or a new color scheme, I know exactly which file to open. Also way friendlier for anyone who wants to hack on it.

Ship

Both landed in v1.7.1. If you already have it:

brew update
brew upgrade hackfetch

Or the curl installer will pull v1.7.1 the next time you run it.

Try it.

0
25

Comments 0

No comments yet. Be the first!