mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-08-16 18:20:50 +03:00
Fix issue 244 (#245)
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
This commit is contained in:
parent
cb3729f94a
commit
3929c9704e
@ -349,9 +349,19 @@ func Init() error {
|
||||
if !ok {
|
||||
return fmt.Errorf(`value for "%s" is not a string: %v`, k, v)
|
||||
}
|
||||
color := tcell.GetColor(strings.ToLower(colorStr))
|
||||
if color == tcell.ColorDefault {
|
||||
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
|
||||
colorStr = strings.ToLower(colorStr)
|
||||
var color tcell.Color
|
||||
if colorStr == "default" {
|
||||
if strings.HasSuffix(k, "bg") {
|
||||
color = tcell.ColorDefault
|
||||
} else {
|
||||
return fmt.Errorf(`"default" is only valid for a background color (color ending in "bg"), not "%s"`, k)
|
||||
}
|
||||
} else {
|
||||
color = tcell.GetColor(colorStr)
|
||||
if color == tcell.ColorDefault {
|
||||
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
|
||||
}
|
||||
}
|
||||
SetColor(k, color)
|
||||
}
|
||||
|
@ -305,6 +305,8 @@ entries_per_page = 20
|
||||
# This section is for changing the COLORS used in Amfora.
|
||||
# These colors only apply if 'color' is enabled above.
|
||||
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
|
||||
# Setting a background to "default" keeps the terminal default
|
||||
# If your terminal has transparency, set any background to "default" to keep it transparent
|
||||
|
||||
# Note that not all colors will work on terminals that do not have truecolor support.
|
||||
# If you want to stick to the standard 16 or 256 colors, you can get
|
||||
@ -323,6 +325,7 @@ entries_per_page = 20
|
||||
# EXAMPLES:
|
||||
# hdg_1 = "green"
|
||||
# hdg_2 = "#5f0000"
|
||||
# bg = "default"
|
||||
|
||||
# Available keys to set:
|
||||
|
||||
|
@ -84,5 +84,50 @@ func GetColor(key string) tcell.Color {
|
||||
func GetColorString(key string) string {
|
||||
themeMu.RLock()
|
||||
defer themeMu.RUnlock()
|
||||
return fmt.Sprintf("#%06x", theme[key].TrueColor().Hex())
|
||||
color := theme[key].TrueColor()
|
||||
if color == tcell.ColorDefault {
|
||||
return "-"
|
||||
}
|
||||
return fmt.Sprintf("#%06x", color.Hex())
|
||||
}
|
||||
|
||||
// GetContrastingColor returns ColorBlack if color is brighter than gray
|
||||
// otherwise returns ColorWhite if color is dimmer than gray
|
||||
// if color is ColorDefault (undefined luminance) this returns ColorDefault
|
||||
func GetContrastingColor(color tcell.Color) tcell.Color {
|
||||
if color == tcell.ColorDefault {
|
||||
// color should never be tcell.ColorDefault
|
||||
// only config keys which end in bg are allowed to be set to default
|
||||
// and the only way the argument of this function is set to ColorDefault
|
||||
// is if both the text and bg of an element in the UI are set to default
|
||||
return tcell.ColorDefault
|
||||
}
|
||||
r, g, b := color.RGB()
|
||||
luminance := (77*r + 150*g + 29*b + 1<<7) >> 8
|
||||
const gray = 119 // The middle gray
|
||||
if luminance > gray {
|
||||
return tcell.ColorBlack
|
||||
}
|
||||
return tcell.ColorWhite
|
||||
}
|
||||
|
||||
// GetTextColor is the Same as GetColor, unless the key is "default".
|
||||
// This happens on focus of a UI element which has a bg of default, in which case
|
||||
// It return tcell.ColorBlack or tcell.ColorWhite, depending on which is more readable
|
||||
func GetTextColor(key, bg string) tcell.Color {
|
||||
themeMu.RLock()
|
||||
defer themeMu.RUnlock()
|
||||
color := theme[key].TrueColor()
|
||||
if color != tcell.ColorDefault {
|
||||
return color
|
||||
}
|
||||
return GetContrastingColor(theme[bg].TrueColor())
|
||||
}
|
||||
|
||||
// GetTextColorString is the Same as GetColorString, unless the key is "default".
|
||||
// This happens on focus of a UI element which has a bg of default, in which case
|
||||
// It return tcell.ColorBlack or tcell.ColorWhite, depending on which is more readable
|
||||
func GetTextColorString(key, bg string) string {
|
||||
color := GetTextColor(key, bg)
|
||||
return fmt.Sprintf("#%06x", color.Hex())
|
||||
}
|
||||
|
@ -302,6 +302,8 @@ entries_per_page = 20
|
||||
# This section is for changing the COLORS used in Amfora.
|
||||
# These colors only apply if 'color' is enabled above.
|
||||
# Colors can be set using a W3C color name, or a hex value such as "#ffffff".
|
||||
# Setting a background to "default" keeps the terminal default
|
||||
# If your terminal has transparency, set any background to "default" to keep it transparent
|
||||
|
||||
# Note that not all colors will work on terminals that do not have truecolor support.
|
||||
# If you want to stick to the standard 16 or 256 colors, you can get
|
||||
@ -320,6 +322,7 @@ entries_per_page = 20
|
||||
# EXAMPLES:
|
||||
# hdg_1 = "green"
|
||||
# hdg_2 = "#5f0000"
|
||||
# bg = "default"
|
||||
|
||||
# Available keys to set:
|
||||
|
||||
|
@ -41,8 +41,10 @@ func bkmkInit() {
|
||||
form.SetLabelColor(config.GetColor("bkmk_modal_label"))
|
||||
form.SetFieldBackgroundColor(config.GetColor("bkmk_modal_field_bg"))
|
||||
form.SetFieldTextColor(config.GetColor("bkmk_modal_field_text"))
|
||||
form.SetFieldBackgroundColorFocused(config.GetColor("bkmk_modal_field_text"))
|
||||
form.SetFieldTextColorFocused(config.GetTextColor("bkmk_modal_field_bg", "bkmk_modal_field_text"))
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
frame := m.GetFrame()
|
||||
frame.SetBorderColor(config.GetColor("bkmk_modal_text"))
|
||||
frame.SetTitleColor(config.GetColor("bkmk_modal_text"))
|
||||
|
@ -106,7 +106,7 @@ func Init(version, commit, builtBy string) {
|
||||
browser.SetTabBackgroundColor(config.GetColor("bg"))
|
||||
browser.SetTabBackgroundColorFocused(config.GetColor("tab_num"))
|
||||
browser.SetTabTextColor(config.GetColor("tab_num"))
|
||||
browser.SetTabTextColorFocused(config.GetColor("bg"))
|
||||
browser.SetTabTextColorFocused(config.GetTextColor("bg", "tab_num"))
|
||||
browser.SetTabSwitcherDivider(
|
||||
"",
|
||||
fmt.Sprintf("[%s:%s]|[-]", config.GetColorString("tab_divider"), config.GetColorString("bg")),
|
||||
|
@ -45,7 +45,7 @@ func dlInit() {
|
||||
chm.SetTextColor(config.GetColor("dl_choice_modal_text"))
|
||||
form := chm.GetForm()
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
frame := chm.GetFrame()
|
||||
frame.SetBorderColor(config.GetColor("dl_choice_modal_text"))
|
||||
frame.SetTitleColor(config.GetColor("dl_choice_modal_text"))
|
||||
@ -56,7 +56,7 @@ func dlInit() {
|
||||
dlm.SetTextColor(config.GetColor("dl_modal_text"))
|
||||
form = dlm.GetForm()
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
frame = dlm.GetFrame()
|
||||
frame.SetBorderColor(config.GetColor("dl_modal_text"))
|
||||
frame.SetTitleColor(config.GetColor("dl_modal_text"))
|
||||
|
@ -49,7 +49,7 @@ func modalInit() {
|
||||
m.SetTextColor(config.GetColor("info_modal_text"))
|
||||
form := m.GetForm()
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
frame := m.GetFrame()
|
||||
frame.SetBorderColor(config.GetColor("info_modal_text"))
|
||||
frame.SetTitleColor(config.GetColor("info_modal_text"))
|
||||
@ -61,7 +61,7 @@ func modalInit() {
|
||||
m.SetTextColor(config.GetColor("error_modal_text"))
|
||||
form = m.GetForm()
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
frame = errorModal.GetFrame()
|
||||
frame.SetBorderColor(config.GetColor("error_modal_text"))
|
||||
frame.SetTitleColor(config.GetColor("error_modal_text"))
|
||||
@ -78,14 +78,14 @@ func modalInit() {
|
||||
form.SetFieldBackgroundColor(config.GetColor("input_modal_field_bg"))
|
||||
form.SetFieldTextColor(config.GetColor("input_modal_field_text"))
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
|
||||
m = yesNoModal
|
||||
m.SetButtonBackgroundColor(config.GetColor("btn_bg"))
|
||||
m.SetButtonTextColor(config.GetColor("btn_text"))
|
||||
form = m.GetForm()
|
||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
||||
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||
} else {
|
||||
m := infoModal
|
||||
m.SetBackgroundColor(tcell.ColorBlack)
|
||||
|
Loading…
Reference in New Issue
Block a user