1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Move settings-related functions from util.go into common_settings.go

This commit is contained in:
Chris Cummer
2019-04-21 21:19:28 -07:00
parent bd2c6e5c9f
commit 88fdf9702b
20 changed files with 105 additions and 99 deletions

View File

@@ -1,6 +1,9 @@
package cfg
import (
"fmt"
"strings"
"github.com/olebedev/config"
)
@@ -10,10 +13,16 @@ type Colors struct {
BorderFocused string
BorderNormal string
Checked string
Foreground string
HighlightFore string
HighlightBack string
Text string
Title string
Rows struct {
Even string
Odd string
}
}
type Module struct {
@@ -29,8 +38,14 @@ type Position struct {
}
type Sigils struct {
CheckedIcon string
UncheckedIcon string
Checkbox struct {
Checked string
Unchecked string
}
Paging struct {
Normal string
Selected string
}
}
type Common struct {
@@ -53,11 +68,12 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
common := Common{
Colors: Colors{
Background: ymlConfig.UString(modulePath+".colors.background", ymlConfig.UString(colorsPath+".background", "black")),
Background: ymlConfig.UString(modulePath+".background", ymlConfig.UString(colorsPath+".background", "black")),
BorderFocusable: ymlConfig.UString(colorsPath+".border.focusable", "red"),
BorderFocused: ymlConfig.UString(colorsPath+".border.focused", "orange"),
BorderNormal: ymlConfig.UString(colorsPath+".border.normal", "gray"),
Checked: ymlConfig.UString(colorsPath+".checked", "white"),
Foreground: ymlConfig.UString(modulePath+".foreground", ymlConfig.UString(colorsPath+".foreground", "white")),
HighlightFore: ymlConfig.UString(colorsPath+".highlight.fore", "black"),
HighlightBack: ymlConfig.UString(colorsPath+".highlight.back", "green"),
Text: ymlConfig.UString(modulePath+".colors.text", ymlConfig.UString(colorsPath+".text", "white")),
@@ -76,16 +92,54 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
Width: ymlConfig.UInt(positionPath + ".width"),
},
Sigils: Sigils{
CheckedIcon: ymlConfig.UString(sigilsPath+".checkedIcon", "x"),
UncheckedIcon: ymlConfig.UString(sigilsPath+".uncheckedIcon", " "),
},
Enabled: ymlConfig.UBool(modulePath+".enabled", false),
FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1),
RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300),
Title: ymlConfig.UString(modulePath+".title", name),
}
common.Colors.Rows.Even = ymlConfig.UString(modulePath+".colors.rows.even", ymlConfig.UString(colorsPath+".rows.even", "white"))
common.Colors.Rows.Odd = ymlConfig.UString(modulePath+".colors.rows.even", ymlConfig.UString(colorsPath+".rows.odd", "lightblue"))
common.Sigils.Checkbox.Checked = ymlConfig.UString(sigilsPath+".Checkbox.Checked", "x")
common.Sigils.Checkbox.Unchecked = ymlConfig.UString(sigilsPath+".Checkbox.Unchecked", " ")
common.Sigils.Paging.Normal = ymlConfig.UString(sigilsPath+".Paging.Normal", ymlConfig.UString("wtf.paging.pageSigil", "*"))
common.Sigils.Paging.Selected = ymlConfig.UString(sigilsPath+".Paging.Select", ymlConfig.UString("wtf.paging.selectedSigil", "_"))
return &common
}
func (common *Common) DefaultFocussedRowColor() string {
return fmt.Sprintf("%s:%s", common.Colors.HighlightFore, common.Colors.HighlightBack)
}
func (common *Common) DefaultRowColor() string {
return fmt.Sprintf("%s:%s", common.Colors.Foreground, common.Colors.Background)
}
func (common *Common) RowColor(idx int) string {
if idx%2 == 0 {
return common.Colors.Rows.Even
}
return common.Colors.Rows.Odd
}
func (common *Common) RightAlignFormat(width int) string {
return fmt.Sprintf("%%%ds", width-1)
}
func (common *Common) SigilStr(len, pos int, width int) string {
sigils := ""
if len > 1 {
sigils = strings.Repeat(common.Sigils.Paging.Normal, pos)
sigils = sigils + common.Sigils.Paging.Selected
sigils = sigils + strings.Repeat(common.Sigils.Paging.Normal, len-1-pos)
sigils = "[lightblue]" + fmt.Sprintf(common.RightAlignFormat(width), sigils) + "[white]"
}
return sigils
}