commit 89b9a9b
delthas
·
2025-03-10 01:01:13 +0000 UTC
parent ae62bb9
Improve color contrast of status text by blending fg and bg to RGB Fixes: https://todo.sr.ht/~delthas/senpai/198
M
go.mod
+1,
-1
1@@ -4,7 +4,7 @@ go 1.18
2
3 require (
4 codeberg.org/emersion/go-scfg v0.1.0
5- git.sr.ht/~rockorager/vaxis v0.12.1-0.20250218200016-0e88f197413a
6+ git.sr.ht/~rockorager/vaxis v0.12.1-0.20250312161844-81636f76af83
7 github.com/containerd/console v1.0.4
8 github.com/delthas/go-libnp v0.0.0-20250105150050-96674b98150e
9 github.com/delthas/go-localeinfo v0.0.0-20240813094314-e5413e186769
M
go.sum
+2,
-2
1@@ -1,7 +1,7 @@
2 codeberg.org/emersion/go-scfg v0.1.0 h1:6dnGU0ZI4gX+O5rMjwhoaySItzHG710eXL5TIQKl+uM=
3 codeberg.org/emersion/go-scfg v0.1.0/go.mod h1:0nooW1ufBB4SlJEdTtiVN9Or+bnNM1icOkQ6Tbrq6O0=
4-git.sr.ht/~rockorager/vaxis v0.12.1-0.20250218200016-0e88f197413a h1:duJRKIJCDSWNUx1A7GmlGK2HcRxbVFrFiXSqAW2EBHE=
5-git.sr.ht/~rockorager/vaxis v0.12.1-0.20250218200016-0e88f197413a/go.mod h1:h94aKek3frIV1hJbdXjqnBqaLkbWXvV+UxAsQHg9bns=
6+git.sr.ht/~rockorager/vaxis v0.12.1-0.20250312161844-81636f76af83 h1:9eVqJxJzMdnpfqfKKjvEvNDpVg6sIBvbI4FdTjhHqx8=
7+git.sr.ht/~rockorager/vaxis v0.12.1-0.20250312161844-81636f76af83/go.mod h1:h94aKek3frIV1hJbdXjqnBqaLkbWXvV+UxAsQHg9bns=
8 github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
9 github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
10 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
M
ui/ui.go
+12,
-8
1@@ -152,19 +152,23 @@ func New(config Config) (ui *UI, colors ConfigColors, err error) {
2 black := ui.vx.QueryColor(vaxis.IndexColor(uint8(0))).Params()
3 gray := ui.vx.QueryColor(vaxis.IndexColor(uint8(8))).Params()
4 white := ui.vx.QueryColor(vaxis.IndexColor(uint8(15))).Params()
5- if len(bg) == 3 && len(gray) == 3 && reflect.DeepEqual(bg, gray) {
6+ fg := ui.vx.QueryForeground().Params()
7+ if len(bg) == 3 && len(fg) == 3 && ui.vx.CanRGB() {
8+ // Interpolate gray from fg and bg to make it slightly more readable against the background than default gray.
9+ p := make([]uint8, 3)
10+ for i := range p {
11+ p[i] = uint8((int(bg[i])*3 + int(fg[i])*2) / 5)
12+ }
13+ ui.config.Colors.Gray = vaxis.RGBColor(p[0], p[1], p[2])
14+ } else if len(bg) == 3 && len(gray) == 3 && reflect.DeepEqual(bg, gray) {
15+ // RGB is not supported.
16 // Color theme with background set to gray: gray would be invisible.
17 if len(black) == 3 && !reflect.DeepEqual(bg, black) {
18 // Black is distinct from background: use that as gray.
19 ui.config.Colors.Gray = vaxis.IndexColor(0)
20 } else if len(white) == 3 && !reflect.DeepEqual(bg, white) {
21- // Black == gray == background color. (Can happen in 8-color themes.)
22- // Use an RGB color as the gray color, interpolated from black and white.
23- p := make([]uint8, 3)
24- for i := range p {
25- p[i] = uint8((int(black[i]) + int(white[i])) / 2)
26- }
27- ui.config.Colors.Gray = vaxis.RGBColor(p[0], p[1], p[2])
28+ // White is distinct from background: use that as white.
29+ ui.config.Colors.Gray = vaxis.IndexColor(15)
30 } else {
31 // Black == gray == background == white. Give up.
32 ui.config.Colors.Gray = ColorDefault