repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

test(nugu): make contrast checks a hard gate

dabb767887c0e333786272c78524901c2b42f075

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+16 / −4 text lines

Diff layout

nugu/nugu.nu

Modified

+16 / −4 text lines

4040# content.important_local: system demands attention → WCAG AA text
4141# content.important_global: important but lighter variant → between AA and large text
4242# ui.*: same semantics but on ui.backdrop instead of content.backdrop
43# content.backdrop on semantic colors: semantic colors used as highlight backgrounds
4445const contrast_thresholds = [
4546 { color: "error", bg: "content.backdrop", min: 4.5 },
4647 { color: "warning", bg: "content.backdrop", min: 3.0 },
4748 { color: "info", bg: "content.backdrop", min: 2.5 },
49 { color: "content.backdrop", bg: "error", min: 4.5 },
50 { color: "content.backdrop", bg: "warning", min: 4.5 },
51 { color: "content.backdrop", bg: "info", min: 4.5 },
4852 { color: "debug", bg: "content.backdrop", min: 3.0 },
4953 { color: "content.normal", bg: "content.backdrop", min: 4.5 },
5054 { color: "content.accent", bg: "content.backdrop", min: 4.5 },
9498 print $"(ansi yellow_bold)WCAG AA: ($theme_name) theme(ansi reset)"
96 if ($failures | length) > 0 {
100 let failure_count = ($failures | length)
102 if $failure_count > 0 {
97103 for f in $failures {
98104 print $" (ansi red)✗(ansi reset) ($f.color) ($f.hex) on ($f.bg_hex) — ($f.ratio):1, need ($f.min):1"
99105 }
100 print $" (ansi red_bold)($failures | length) warnings(ansi reset)"
106 print $" (ansi red_bold)($failure_count) failures(ansi reset)"
101107 } else {
102108 print $" (ansi green)✓ all colors pass(ansi reset)"
103109 }
104110 print ""
111 $failure_count
107114export def check [] {
108115 print ""
109 validate-theme (new) "dark"
110 validate-theme (new --light) "light"
116 let failure_count = ([
117 (validate-theme (new) "dark")
118 (validate-theme (new --light) "light")
119 ] | math sum)
120 if $failure_count > 0 {
121 error make { msg: $"($failure_count) Nugu contrast checks failed" }
122 }
113125def readable-textcolor [bg: string] {