What is it?
Code Critic is a small desktop pet that lives at the bottom corner of your screen and reacts to the quality of your Rust code. Think Tamagotchi, but instead of feeding it, you feed it clean code.
It runs cargo check on your project every couple of second and picks an animation based on what it finds. The worse your code looks, the more distressed the the Rust mascot Ferris gets.
The States
The crab has five moods, and they tell you everything you need to know about your code at a glance:
Happy: no errors, fewer than 10 warnings.
Warning: more than 10 warnings. Speeds up as the count climbs.
Panic: any compile error. Stops pacing entirely.
Excited: you clicked on it.
Sleep: no file modified in the last 5 minutes.
The Irony
The project is written in Python. It is a Python tool for Rust. I don't know, but this does not feel very right...
How it Works
The two interesting pieces are the code checker and the sleep detector.
The code checker runs cargo check in a background thread and counts lines starting with warning: or error: using regex. It fires every second but skips the check if the previous run is still in progress, so it never queues up.
The sleep detector uses a small shell trick to find the most recently modified tracked or untracked file in the git repo:
git ls-files -c -o --exclude-standard -z | xargs -0 stat --format='%Y' | sort -n | tail -n 1
If that timestamp is older than 5 minutes, the crab goes to sleep. When you save a file again, the next check wakes it up immediately.
The warning animation gets progressively faster as warnings pile up. Both the GIF playback speed and the pacing interval are scaled by warning count, so 50 warnings looks noticeably worse than 11.
Stack
- Python with PyQt6 for the window and animation
QThreadfor runningcargo checkand the file-modification check off the main threadQTimerfor the pacing loop, code check loop, and sleep check loop- Five GIF animations for the crab states
Credits
The crab animations were made by Viola Wolf