mirror of
https://github.com/makew0rld/amfora.git
synced 2024-09-27 23:05:55 -04: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,10 +349,20 @@ func Init() error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf(`value for "%s" is not a string: %v`, k, v)
|
return fmt.Errorf(`value for "%s" is not a string: %v`, k, v)
|
||||||
}
|
}
|
||||||
color := tcell.GetColor(strings.ToLower(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 {
|
if color == tcell.ColorDefault {
|
||||||
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
|
return fmt.Errorf(`invalid color format for "%s": %s`, k, colorStr)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SetColor(k, color)
|
SetColor(k, color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,6 +305,8 @@ entries_per_page = 20
|
|||||||
# This section is for changing the COLORS used in Amfora.
|
# This section is for changing the COLORS used in Amfora.
|
||||||
# These colors only apply if 'color' is enabled above.
|
# 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".
|
# 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.
|
# 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
|
# If you want to stick to the standard 16 or 256 colors, you can get
|
||||||
@ -323,6 +325,7 @@ entries_per_page = 20
|
|||||||
# EXAMPLES:
|
# EXAMPLES:
|
||||||
# hdg_1 = "green"
|
# hdg_1 = "green"
|
||||||
# hdg_2 = "#5f0000"
|
# hdg_2 = "#5f0000"
|
||||||
|
# bg = "default"
|
||||||
|
|
||||||
# Available keys to set:
|
# Available keys to set:
|
||||||
|
|
||||||
|
@ -84,5 +84,50 @@ func GetColor(key string) tcell.Color {
|
|||||||
func GetColorString(key string) string {
|
func GetColorString(key string) string {
|
||||||
themeMu.RLock()
|
themeMu.RLock()
|
||||||
defer themeMu.RUnlock()
|
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.
|
# This section is for changing the COLORS used in Amfora.
|
||||||
# These colors only apply if 'color' is enabled above.
|
# 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".
|
# 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.
|
# 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
|
# If you want to stick to the standard 16 or 256 colors, you can get
|
||||||
@ -320,6 +322,7 @@ entries_per_page = 20
|
|||||||
# EXAMPLES:
|
# EXAMPLES:
|
||||||
# hdg_1 = "green"
|
# hdg_1 = "green"
|
||||||
# hdg_2 = "#5f0000"
|
# hdg_2 = "#5f0000"
|
||||||
|
# bg = "default"
|
||||||
|
|
||||||
# Available keys to set:
|
# Available keys to set:
|
||||||
|
|
||||||
|
@ -41,8 +41,10 @@ func bkmkInit() {
|
|||||||
form.SetLabelColor(config.GetColor("bkmk_modal_label"))
|
form.SetLabelColor(config.GetColor("bkmk_modal_label"))
|
||||||
form.SetFieldBackgroundColor(config.GetColor("bkmk_modal_field_bg"))
|
form.SetFieldBackgroundColor(config.GetColor("bkmk_modal_field_bg"))
|
||||||
form.SetFieldTextColor(config.GetColor("bkmk_modal_field_text"))
|
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.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
frame := m.GetFrame()
|
frame := m.GetFrame()
|
||||||
frame.SetBorderColor(config.GetColor("bkmk_modal_text"))
|
frame.SetBorderColor(config.GetColor("bkmk_modal_text"))
|
||||||
frame.SetTitleColor(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.SetTabBackgroundColor(config.GetColor("bg"))
|
||||||
browser.SetTabBackgroundColorFocused(config.GetColor("tab_num"))
|
browser.SetTabBackgroundColorFocused(config.GetColor("tab_num"))
|
||||||
browser.SetTabTextColor(config.GetColor("tab_num"))
|
browser.SetTabTextColor(config.GetColor("tab_num"))
|
||||||
browser.SetTabTextColorFocused(config.GetColor("bg"))
|
browser.SetTabTextColorFocused(config.GetTextColor("bg", "tab_num"))
|
||||||
browser.SetTabSwitcherDivider(
|
browser.SetTabSwitcherDivider(
|
||||||
"",
|
"",
|
||||||
fmt.Sprintf("[%s:%s]|[-]", config.GetColorString("tab_divider"), config.GetColorString("bg")),
|
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"))
|
chm.SetTextColor(config.GetColor("dl_choice_modal_text"))
|
||||||
form := chm.GetForm()
|
form := chm.GetForm()
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
frame := chm.GetFrame()
|
frame := chm.GetFrame()
|
||||||
frame.SetBorderColor(config.GetColor("dl_choice_modal_text"))
|
frame.SetBorderColor(config.GetColor("dl_choice_modal_text"))
|
||||||
frame.SetTitleColor(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"))
|
dlm.SetTextColor(config.GetColor("dl_modal_text"))
|
||||||
form = dlm.GetForm()
|
form = dlm.GetForm()
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
frame = dlm.GetFrame()
|
frame = dlm.GetFrame()
|
||||||
frame.SetBorderColor(config.GetColor("dl_modal_text"))
|
frame.SetBorderColor(config.GetColor("dl_modal_text"))
|
||||||
frame.SetTitleColor(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"))
|
m.SetTextColor(config.GetColor("info_modal_text"))
|
||||||
form := m.GetForm()
|
form := m.GetForm()
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_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 := m.GetFrame()
|
||||||
frame.SetBorderColor(config.GetColor("info_modal_text"))
|
frame.SetBorderColor(config.GetColor("info_modal_text"))
|
||||||
frame.SetTitleColor(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"))
|
m.SetTextColor(config.GetColor("error_modal_text"))
|
||||||
form = m.GetForm()
|
form = m.GetForm()
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
frame = errorModal.GetFrame()
|
frame = errorModal.GetFrame()
|
||||||
frame.SetBorderColor(config.GetColor("error_modal_text"))
|
frame.SetBorderColor(config.GetColor("error_modal_text"))
|
||||||
frame.SetTitleColor(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.SetFieldBackgroundColor(config.GetColor("input_modal_field_bg"))
|
||||||
form.SetFieldTextColor(config.GetColor("input_modal_field_text"))
|
form.SetFieldTextColor(config.GetColor("input_modal_field_text"))
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
|
|
||||||
m = yesNoModal
|
m = yesNoModal
|
||||||
m.SetButtonBackgroundColor(config.GetColor("btn_bg"))
|
m.SetButtonBackgroundColor(config.GetColor("btn_bg"))
|
||||||
m.SetButtonTextColor(config.GetColor("btn_text"))
|
m.SetButtonTextColor(config.GetColor("btn_text"))
|
||||||
form = m.GetForm()
|
form = m.GetForm()
|
||||||
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
|
||||||
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
|
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
|
||||||
} else {
|
} else {
|
||||||
m := infoModal
|
m := infoModal
|
||||||
m.SetBackgroundColor(tcell.ColorBlack)
|
m.SetBackgroundColor(tcell.ColorBlack)
|
||||||
|
Loading…
Reference in New Issue
Block a user