wail: Readable Terminal Colors from Any Wallpaper
wail turns a wallpaper into a 16-color terminal palette. It’s a Rust library and command-line tool in the same family as pywal, and its flags, output files, and template syntax follow pywal’s, so it can stand in for wal in most setups. Version 1.1.0 is on crates.io.
cargo install wail
wail -i ~/Pictures/wallpapers/forest.jpg
Why
I built wail for wraith, my Hyprland desktop, which recolors everything from the current wallpaper. It used pywal, and pywal’s accent colors weren’t always readable, because it shades colors in RGB without checking contrast. In one wraith setup, color1 came out as #4A4340 on a #0C1015 background, about 2:1. The bright colors, color9 through color14, were straight copies of the normal ones.
wail fixes that by enforcing contrast. Every accent has to hit at least 4.5:1 against the background, the bright accents 6:1, and the foreground 10:1. color8 is held between 3:1 and 4.5:1 on purpose, so it reads as dim without disappearing.
How it works
All the color work happens in OKLab and OKLCH, which track how bright and how colorful things look to people much better than RGB does.
- Shrink the image so its longest side is about 256 pixels.
- Group the pixels into 16 clusters with k-means.
- Pick the background from the darkest sizable cluster, keeping a hint of the wallpaper’s tint without letting it get colorful.
- Score the rest by how much of the image they cover and how saturated they are, and keep the six best that still look distinct from each other.
- Adjust only lightness until each color meets its contrast target, so hues stay put.
The result is deterministic. The same image and flags give the same palette every time. Pass -l for a light palette, or --ansi if you want color1 through color6 to line up with red, green, yellow, blue, magenta, and cyan instead of ranking by prominence.
Samples
Here are the palettes wail picked from six of my wallpapers. Version 1.1.0 added --polaroid, which draws a palette as a pixel-art polaroid: the wallpaper as a small photo, then color0 through color7 in the first row of swatches and color8 through color15 in the second.
wail -i frieren-grave.jpg --polaroid frieren-grave.png
No dependencies
wail has no crate dependencies at all. The PNG and JPEG decoders, the color math, the JSON output, and the template renderer are all written in-house, and the binary depends on nothing but Rust’s standard library. That also makes it quick: on 4K wallpapers it decodes and builds a palette in about 19 ms for a JPEG and 97 ms for a PNG on a Ryzen 7 5800X.
Switching from pywal
wail writes colors.json, colors, and sequences in pywal’s formats, and it renders the same {color1.strip}-style templates. By default it keeps its own directories (~/.cache/wail and ~/.config/wail/templates), so the two can live side by side. A tool that can’t change its paths can pass --out ~/.cache/wal --templates ~/.config/wal/templates to write over pywal’s files.
It doesn’t do everything pywal does. There are no built-in themes, backends, hooks, or wallpaper setting, and pywal’s built-in templates aren’t included, so you supply your own. The README covers the details, including using wail as a library.
# EOF