2020-07-28 16:58:32 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
2020-10-11 16:07:31 -04:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2020-07-28 16:58:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Functions to allow themeing configuration.
|
2020-08-07 12:27:50 -04:00
|
|
|
// UI element colors are mapped to a string key, such as "error" or "tab_bg"
|
2020-07-28 16:58:32 -04:00
|
|
|
// These are the same keys used in the config file.
|
|
|
|
|
|
|
|
var themeMu = sync.RWMutex{}
|
|
|
|
var theme = map[string]tcell.Color{
|
|
|
|
// Default values below
|
|
|
|
|
|
|
|
"bg": tcell.ColorBlack, // Used for cview.Styles.PrimitiveBackgroundColor
|
|
|
|
"tab_num": tcell.Color30, // xterm:Turquoise4, #008787
|
|
|
|
"tab_divider": tcell.ColorWhite,
|
|
|
|
"bottombar_label": tcell.Color30,
|
|
|
|
"bottombar_text": tcell.ColorBlack,
|
|
|
|
"bottombar_bg": tcell.ColorWhite,
|
|
|
|
|
|
|
|
// Modals
|
|
|
|
"btn_bg": tcell.ColorNavy, // All modal buttons
|
|
|
|
"btn_text": tcell.ColorWhite,
|
|
|
|
|
2020-11-27 17:01:29 -05:00
|
|
|
"dl_choice_modal_bg": tcell.ColorPurple,
|
|
|
|
"dl_choice_modal_text": tcell.ColorWhite,
|
|
|
|
"dl_modal_bg": tcell.Color130, // xterm:DarkOrange3, #af5f00
|
|
|
|
"dl_modal_text": tcell.ColorWhite,
|
|
|
|
"info_modal_bg": tcell.ColorGray,
|
|
|
|
"info_modal_text": tcell.ColorWhite,
|
|
|
|
"error_modal_bg": tcell.ColorMaroon,
|
|
|
|
"error_modal_text": tcell.ColorWhite,
|
|
|
|
"yesno_modal_bg": tcell.ColorPurple,
|
|
|
|
"yesno_modal_text": tcell.ColorWhite,
|
|
|
|
"tofu_modal_bg": tcell.ColorMaroon,
|
|
|
|
"tofu_modal_text": tcell.ColorWhite,
|
|
|
|
"subscription_modal_bg": tcell.Color61, // xterm:SlateBlue3, #5f5faf
|
|
|
|
"subscription_modal_text": tcell.ColorWhite,
|
2020-07-28 16:58:32 -04:00
|
|
|
|
|
|
|
"input_modal_bg": tcell.ColorGreen,
|
|
|
|
"input_modal_text": tcell.ColorWhite,
|
|
|
|
"input_modal_field_bg": tcell.ColorBlue,
|
|
|
|
"input_modal_field_text": tcell.ColorWhite,
|
|
|
|
|
|
|
|
"bkmk_modal_bg": tcell.ColorTeal,
|
|
|
|
"bkmk_modal_text": tcell.ColorWhite,
|
|
|
|
"bkmk_modal_label": tcell.ColorYellow,
|
|
|
|
"bkmk_modal_field_bg": tcell.ColorBlue,
|
|
|
|
"bkmk_modal_field_text": tcell.ColorWhite,
|
|
|
|
|
|
|
|
"hdg_1": tcell.ColorRed,
|
|
|
|
"hdg_2": tcell.ColorLime,
|
|
|
|
"hdg_3": tcell.ColorFuchsia,
|
|
|
|
"amfora_link": tcell.Color33, // xterm:DodgerBlue1, #0087ff
|
|
|
|
"foreign_link": tcell.Color92, // xterm:DarkViolet, #8700d7
|
|
|
|
"link_number": tcell.ColorSilver,
|
|
|
|
"regular_text": tcell.ColorWhite,
|
|
|
|
"quote_text": tcell.ColorWhite,
|
2020-11-19 00:07:56 -05:00
|
|
|
"preformatted_text": tcell.Color229, // xterm:Wheat1, #ffffaf
|
2020-07-28 16:58:32 -04:00
|
|
|
"list_text": tcell.ColorWhite,
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetColor(key string, color tcell.Color) {
|
|
|
|
themeMu.Lock()
|
|
|
|
theme[key] = color
|
2020-08-07 12:27:50 -04:00
|
|
|
themeMu.Unlock()
|
2020-07-28 16:58:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetColor will return tcell.ColorBlack if there is no color for the provided key.
|
|
|
|
func GetColor(key string) tcell.Color {
|
|
|
|
themeMu.RLock()
|
|
|
|
defer themeMu.RUnlock()
|
2020-12-28 15:59:18 -05:00
|
|
|
return theme[key].TrueColor()
|
2020-07-28 16:58:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetColorString returns a string that can be used in a cview color tag,
|
|
|
|
// for the given theme key.
|
|
|
|
// It will return "#000000" if there is no color for the provided key.
|
|
|
|
func GetColorString(key string) string {
|
|
|
|
themeMu.RLock()
|
|
|
|
defer themeMu.RUnlock()
|
2020-12-28 15:59:18 -05:00
|
|
|
return fmt.Sprintf("#%06x", theme[key].TrueColor().Hex())
|
2020-07-28 16:58:32 -04:00
|
|
|
}
|