hints kitten: Workaround for some broken light color themes that make the hints text color too low contrast to read

Fixes #7330
This commit is contained in:
Kovid Goyal
2025-01-17 20:22:10 +05:30
parent 182bd9c7b3
commit 8931062a70
5 changed files with 77 additions and 2 deletions

View File

@@ -111,7 +111,28 @@ func decode_hint(x string, alphabet string) (ans int) {
return
}
func as_rgb(c uint32) [3]float32 {
return [3]float32{float32((c>>16)&255) / 255.0, float32((c>>8)&255) / 255.0, float32(c&255) / 255.0}
}
func hints_text_color(confval string) (ans string) {
ans = confval
if ans == "auto" {
ans = "bright-gray"
if bc, err := tui.ReadBasicColors(); err == nil {
bg := as_rgb(bc.Background)
c15 := as_rgb(bc.Color15)
c8 := as_rgb(bc.Color8)
if utils.RGBContrast(bg[0], bg[1], bg[2], c8[0], c8[1], c8[2]) > utils.RGBContrast(bg[0], bg[1], bg[2], c15[0], c15[1], c15[2]) {
ans = "bright-black"
}
}
}
return
}
func main(_ *cli.Command, o *Options, args []string) (rc int, err error) {
o.HintsTextColor = hints_text_color(o.HintsTextColor)
output := tui.KittenOutputSerializer()
if tty.IsTerminal(os.Stdin.Fd()) {
return 1, fmt.Errorf("You must pass the text to be hinted on STDIN")

View File

@@ -229,11 +229,11 @@ color.
--hints-text-color
default=bright-gray
default=auto
type=str
The foreground color for text pointed to by the hints. You can use color names or hex values. For the eight basic
named terminal colors you can also use the :code:`bright-` prefix to get the bright variant of the
color.
color. The default is to pick a suitable color automatically.
--customize-processing