diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/udt-accent | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/bin/udt-accent b/bin/udt-accent index 1a222b5..75058df 100755 --- a/bin/udt-accent +++ b/bin/udt-accent @@ -25,7 +25,7 @@ from pathlib import Path # palette/<scheme>.conf and palette/roles-<scheme>.conf, so the accents this # snaps to follow whatever scheme is selected. Regenerate with ./install.sh. sys.path.insert(0, str(Path(__file__).resolve().parent)) -from udt_colors import ACCENTS, FALLBACK, PALETTE # noqa: E402 +from udt_colors import ACCENTS, FALLBACK, PALETTE, SCHEME # noqa: E402 MIN_CHROMA = 10.0 @@ -204,7 +204,7 @@ def write_qml(name): content = ( "// Generated by udt-accent. Do not edit.\n" "//\n" - "// The Catppuccin Macchiato palette from palette.rasi, plus the accent\n" + f"// The {SCHEME} palette from palette.rasi, plus the accent\n" "// currently snapped from the wallpaper. Import it from a quickshell\n" "// component and watch this file to follow theme changes.\n" "pragma Singleton\n" @@ -307,9 +307,14 @@ def selftest(): got = snap(hexval) assert got == name, f"{name} ({hexval}) snapped to {got}" - # Representative real-world inputs. - assert snap("#ff8800") == "peach", snap("#ff8800") - assert snap("#00cc44") == "green", snap("#00cc44") + # Representative real-world inputs. Asserted by hue rather than by name: + # the accent table is generated, so the colour an orange input snaps to is + # called "peach" under Catppuccin and "orange" under Tokyo Night. + for probe in ("#ff8800", "#00cc44", "#3366ff"): + got = snap(probe) + delta = abs(_hue(ACCENTS[got]) - _hue(probe)) + delta = min(delta, 2 * math.pi - delta) + assert delta < 0.6, f"{probe} snapped to {got}, {delta:.2f} rad away" # A near-grey has an unstable hue angle and must take the fallback. assert snap("#888888") == FALLBACK, snap("#888888") @@ -320,7 +325,13 @@ def selftest(): for name in ACCENTS: before, after = hue_neighbours(name) assert len({before, name, after}) == 3, (name, before, after) - assert hue_neighbours("peach") == ("red", "yellow"), hue_neighbours("peach") + # Neighbours are the adjacent hues on the wheel, so each sits nearer to + # the accent than the accent's opposite does. + for name in ACCENTS: + before, after = hue_neighbours(name) + for neighbour in (before, after): + delta = abs(_hue(ACCENTS[neighbour]) - _hue(ACCENTS[name])) + assert min(delta, 2 * math.pi - delta) < math.pi, (name, neighbour) print("selftest OK") |
