mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 00:08:04 +02:00
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:
@@ -20,6 +20,37 @@ var RunningAsUI = sync.OnceValue(func() bool {
|
||||
return os.Getenv("KITTEN_RUNNING_AS_UI") != ""
|
||||
})
|
||||
|
||||
type BasicColors struct {
|
||||
Foreground uint32 `json:"foreground"`
|
||||
Background uint32 `json:"background"`
|
||||
Color0 uint32 `json:"color0"`
|
||||
Color1 uint32 `json:"color1"`
|
||||
Color2 uint32 `json:"color2"`
|
||||
Color3 uint32 `json:"color3"`
|
||||
Color4 uint32 `json:"color4"`
|
||||
Color5 uint32 `json:"color5"`
|
||||
Color6 uint32 `json:"color6"`
|
||||
Color7 uint32 `json:"color7"`
|
||||
Color8 uint32 `json:"color8"`
|
||||
Color9 uint32 `json:"color9"`
|
||||
Color10 uint32 `json:"color10"`
|
||||
Color11 uint32 `json:"color11"`
|
||||
Color12 uint32 `json:"color12"`
|
||||
Color13 uint32 `json:"color13"`
|
||||
Color14 uint32 `json:"color14"`
|
||||
Color15 uint32 `json:"color15"`
|
||||
}
|
||||
|
||||
func ReadBasicColors() (ans BasicColors, err error) {
|
||||
q := os.Getenv("KITTY_BASIC_COLORS")
|
||||
if q == "" {
|
||||
err = fmt.Errorf("No KITTY_BASIC_COLORS env var")
|
||||
} else {
|
||||
err = json.Unmarshal(utils.UnsafeStringToBytes(q), &ans)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func PrepareRootCmd(root *cli.Command) {
|
||||
if RunningAsUI() {
|
||||
root.CallbackOnError = func(cmd *cli.Command, err error, during_parsing bool, exit_code int) int {
|
||||
|
||||
21
tools/utils/colors.go
Normal file
21
tools/utils/colors.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func RGBLuminance(r, g, b float32) float32 {
|
||||
// From ITU BT 601 https://www.itu.int/rec/R-REC-BT.601
|
||||
return 0.299*r + 0.587*g + 0.114*b
|
||||
}
|
||||
|
||||
func RGBContrast(r1, g1, b1, r2, g2, b2 float32) float32 {
|
||||
al := RGBLuminance(r1, g1, b1)
|
||||
bl := RGBLuminance(r2, g2, b2)
|
||||
if al < bl {
|
||||
al, bl = bl, al
|
||||
}
|
||||
return (al + 0.05) / (bl + 0.05)
|
||||
}
|
||||
Reference in New Issue
Block a user