isaac@overacker:~$ Isaac Overacker

$ cat wail-readable-terminal-colors-from-any-wallpaper.md

wail: Readable Terminal Colors from Any Wallpaper

# #Open Source#Rust#Side Projects#Linux

Polaroid of a Frieren wallpaper in white and blue, with a palette of blues, slate, and pale pinks

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.

  1. Shrink the image so its longest side is about 256 pixels.
  2. Group the pixels into 16 clusters with k-means.
  3. Pick the background from the darkest sizable cluster, keeping a hint of the wallpaper’s tint without letting it get colorful.
  4. 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.
  5. 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
Polaroid of Frieren under a huge tree against a purple sunset, with a palette of purples, periwinkle, and coral pinks Polaroid of Kiki from Kiki's Delivery Service lying in the grass, with a palette of greens, blue, coral red, and grays Polaroid of Chihiro and Haku from Spirited Away, with a palette of teals, blues, and orange Polaroid of a Dandadan wallpaper in pink and red, with a palette of reds and pinks Polaroid of Joker and the Persona 5 cast in red, yellow, and black, with a palette of red, yellows, and golds Polaroid of a huge tree over a field at sunset, with a palette of oranges, yellow-green, teal, and sky blue

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

User Account Control

A website wants to change how it looks

If you started this action, continue.

overacker.me light theme

Verified publisher: Isaac Overacker

Details

Requested change: from the terminal to Frutiger Aero

User Account Control helps stop unauthorized changes to your aesthetic.