config: refactor

This commit is contained in:
ayn2op 2025-07-12 15:10:59 -04:00
parent 00c4c6386d
commit 7fe4ff7df1
2 changed files with 40 additions and 37 deletions

39
internal/config/border.go Normal file
View file

@ -0,0 +1,39 @@
package config
import "github.com/ayn2op/tview"
type (
TitleTheme struct {
ThemeStyle
Alignment AlignmentWrapper `toml:"alignment"`
}
BorderTheme struct {
ThemeStyle
Enabled bool `toml:"enabled"`
Padding [4]int `toml:"padding"`
Set BorderSetWrapper `toml:"set"`
}
)
type BorderSetWrapper struct{ tview.BorderSet }
func (bw *BorderSetWrapper) UnmarshalTOML(val any) error {
s, ok := val.(string)
if !ok {
return errInvalidType
}
switch s {
case "plain":
bw.BorderSet = tview.BorderSetPlain()
case "round":
bw.BorderSet = tview.BorderSetRound()
case "thick":
bw.BorderSet = tview.BorderSetThick()
case "double":
bw.BorderSet = tview.BorderSetDouble()
}
return nil
}

View file

@ -7,31 +7,7 @@ import (
"github.com/gdamore/tcell/v2"
)
var (
errInvalidType = errors.New("invalid type")
)
type BorderSetWrapper struct{ tview.BorderSet }
func (bw *BorderSetWrapper) UnmarshalTOML(val any) error {
s, ok := val.(string)
if !ok {
return errInvalidType
}
switch s {
case "plain":
bw.BorderSet = tview.BorderSetPlain()
case "round":
bw.BorderSet = tview.BorderSetRound()
case "thick":
bw.BorderSet = tview.BorderSetThick()
case "double":
bw.BorderSet = tview.BorderSetDouble()
}
return nil
}
var errInvalidType = errors.New("invalid type")
type AlignmentWrapper struct{ tview.Alignment }
@ -113,18 +89,6 @@ type (
ActiveStyle StyleWrapper `toml:"active_style"`
}
TitleTheme struct {
ThemeStyle
Alignment AlignmentWrapper `toml:"alignment"`
}
BorderTheme struct {
ThemeStyle
Enabled bool `toml:"enabled"`
Padding [4]int `toml:"padding"`
Set BorderSetWrapper `toml:"set"`
}
GuildsTreeTheme struct {
AutoExpandFolders bool `toml:"auto_expand_folders"`
Graphics bool `toml:"graphics"`