mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Common settings implemented
This commit is contained in:
parent
2ed3c087b8
commit
f09d08bda2
@ -13,6 +13,7 @@ type Colors struct {
|
|||||||
HighlightFore string
|
HighlightFore string
|
||||||
HighlightBack string
|
HighlightBack string
|
||||||
Text string
|
Text string
|
||||||
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
@ -33,21 +34,27 @@ type Common struct {
|
|||||||
Position
|
Position
|
||||||
|
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
FocusChar int
|
||||||
RefreshInterval int
|
RefreshInterval int
|
||||||
Title string
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) *Common {
|
func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) *Common {
|
||||||
|
colorsPath := "wtf.colors"
|
||||||
|
modulePath := "wtf.mods." + configKey
|
||||||
|
positionPath := "wtf.mods." + configKey + ".position"
|
||||||
|
|
||||||
common := Common{
|
common := Common{
|
||||||
Colors: Colors{
|
Colors: Colors{
|
||||||
Background: ymlConfig.UString("wtf.colors.background", "black"),
|
Background: ymlConfig.UString(modulePath+".colors.background", ymlConfig.UString(colorsPath+".background", "black")),
|
||||||
BorderFocusable: ymlConfig.UString("wtf.colors.border.focusable"),
|
BorderFocusable: ymlConfig.UString(colorsPath+".border.focusable", "red"),
|
||||||
BorderFocused: ymlConfig.UString("wtf.colors.border.focused"),
|
BorderFocused: ymlConfig.UString(colorsPath+".border.focused", "orange"),
|
||||||
BorderNormal: ymlConfig.UString("wtf.colors.border.normal"),
|
BorderNormal: ymlConfig.UString(colorsPath+".border.normal", "gray"),
|
||||||
Checked: ymlConfig.UString("wtf.colors.checked"),
|
Checked: ymlConfig.UString(colorsPath+".checked", "gray"),
|
||||||
HighlightFore: ymlConfig.UString("wtf.colors.highlight.fore"),
|
HighlightFore: ymlConfig.UString(colorsPath+".highlight.fore", "black"),
|
||||||
HighlightBack: ymlConfig.UString("wtf.colors.highlight.back"),
|
HighlightBack: ymlConfig.UString(colorsPath+".highlight.back", "green"),
|
||||||
Text: ymlConfig.UString("wtf.colors.text", "white"),
|
Text: ymlConfig.UString(modulePath+".colors.text", ymlConfig.UString(colorsPath+".text", "white")),
|
||||||
|
Title: ymlConfig.UString(modulePath+".colors.title", ymlConfig.UString(colorsPath+".title", "white")),
|
||||||
},
|
},
|
||||||
|
|
||||||
Module: Module{
|
Module: Module{
|
||||||
@ -55,7 +62,17 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config)
|
|||||||
Name: name,
|
Name: name,
|
||||||
},
|
},
|
||||||
|
|
||||||
Position: Position{},
|
Position: Position{
|
||||||
|
Height: ymlConfig.UInt(positionPath + ".height"),
|
||||||
|
Left: ymlConfig.UInt(positionPath + ".left"),
|
||||||
|
Top: ymlConfig.UInt(positionPath + ".top"),
|
||||||
|
Width: ymlConfig.UInt(positionPath + ".width"),
|
||||||
|
},
|
||||||
|
|
||||||
|
Enabled: ymlConfig.UBool(modulePath+".enabled", false),
|
||||||
|
FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1),
|
||||||
|
RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300),
|
||||||
|
Title: ymlConfig.UString(modulePath+".title", name),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &common
|
return &common
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigDirV1 defines the path to the first version of configuration. Do not use this
|
// ConfigDirV1 defines the path to the first version of configuration. Do not use this
|
||||||
@ -20,8 +22,8 @@ const ConfigDirV2 = "~/.config/wtf/"
|
|||||||
// MigrateOldConfig copies any existing configuration from the old location
|
// MigrateOldConfig copies any existing configuration from the old location
|
||||||
// to the new, XDG-compatible location
|
// to the new, XDG-compatible location
|
||||||
func MigrateOldConfig() {
|
func MigrateOldConfig() {
|
||||||
srcDir, _ := wtf.ExpandHomeDir(ConfigDirV1)
|
srcDir, _ := expandHomeDir(ConfigDirV1)
|
||||||
destDir, _ := wtf.ExpandHomeDir(ConfigDirV2)
|
destDir, _ := expandHomeDir(ConfigDirV2)
|
||||||
|
|
||||||
// If the old config directory doesn't exist, do not move
|
// If the old config directory doesn't exist, do not move
|
||||||
if _, err := os.Stat(srcDir); os.IsNotExist(err) {
|
if _, err := os.Stat(srcDir); os.IsNotExist(err) {
|
||||||
@ -52,7 +54,7 @@ func MigrateOldConfig() {
|
|||||||
|
|
||||||
// ConfigDir returns the absolute path to the configuration directory
|
// ConfigDir returns the absolute path to the configuration directory
|
||||||
func ConfigDir() (string, error) {
|
func ConfigDir() (string, error) {
|
||||||
configDir, err := wtf.ExpandHomeDir(ConfigDirV2)
|
configDir, err := expandHomeDir(ConfigDirV2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -120,7 +122,7 @@ func CreateFile(fileName string) (string, error) {
|
|||||||
|
|
||||||
// LoadConfigFile loads the config.yml file to configure the app
|
// LoadConfigFile loads the config.yml file to configure the app
|
||||||
func LoadConfigFile(filePath string) *config.Config {
|
func LoadConfigFile(filePath string) *config.Config {
|
||||||
absPath, _ := wtf.ExpandHomeDir(filePath)
|
absPath, _ := expandHomeDir(filePath)
|
||||||
|
|
||||||
cfg, err := config.ParseYamlFile(absPath)
|
cfg, err := config.ParseYamlFile(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -196,3 +198,43 @@ const simpleConfig = `wtf:
|
|||||||
width: 1
|
width: 1
|
||||||
refreshInterval: 30
|
refreshInterval: 30
|
||||||
`
|
`
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
// Expand expands the path to include the home directory if the path
|
||||||
|
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
|
||||||
|
// returned as-is.
|
||||||
|
func expandHomeDir(path string) (string, error) {
|
||||||
|
if len(path) == 0 {
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if path[0] != '~' {
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
|
||||||
|
return "", errors.New("cannot expand user-specific home dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := home()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath.Join(dir, path[1:]), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dir returns the home directory for the executing user.
|
||||||
|
// An error is returned if a home directory cannot be detected.
|
||||||
|
func home() (string, error) {
|
||||||
|
currentUser, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if currentUser.HomeDir == "" {
|
||||||
|
return "", errors.New("cannot find user-specific home dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUser.HomeDir, nil
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "Logs", "logger", true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
filePath: logFilePath(),
|
filePath: logFilePath(),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
22
main.go
22
main.go
@ -151,7 +151,7 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
|||||||
loadConfigFile(absPath)
|
loadConfigFile(absPath)
|
||||||
|
|
||||||
widgets := makeWidgets(app, pages)
|
widgets := makeWidgets(app, pages)
|
||||||
validateWidgets(widgets)
|
wtf.ValidateWidgets(widgets)
|
||||||
|
|
||||||
initializeFocusTracker(app, widgets)
|
initializeFocusTracker(app, widgets)
|
||||||
|
|
||||||
@ -342,15 +342,15 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) []wtf.Wtfable {
|
|||||||
return widgets
|
return widgets
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all the loaded widgets are valid for display
|
// // Check that all the loaded widgets are valid for display
|
||||||
func validateWidgets(widgets []wtf.Wtfable) {
|
// func validateWidgets(widgets []wtf.Wtfable) {
|
||||||
for _, widget := range widgets {
|
// for _, widget := range widgets {
|
||||||
if widget.Enabled() && !widget.IsPositionable() {
|
// if widget.Enabled() && !widget.IsPositionable() {
|
||||||
errStr := fmt.Sprintf("Widget config has invalid values: %s", widget.Key())
|
// errStr := fmt.Sprintf("Widget config has invalid values: %s", widget.Key())
|
||||||
log.Fatalln(errStr)
|
// log.Fatalln(errStr)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* -------------------- Main -------------------- */
|
/* -------------------- Main -------------------- */
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ func main() {
|
|||||||
pages := tview.NewPages()
|
pages := tview.NewPages()
|
||||||
|
|
||||||
widgets := makeWidgets(app, pages)
|
widgets := makeWidgets(app, pages)
|
||||||
validateWidgets(widgets)
|
wtf.ValidateWidgets(widgets)
|
||||||
|
|
||||||
initializeFocusTracker(app, widgets)
|
initializeFocusTracker(app, widgets)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
Client: NewClient(settings.apiKey),
|
Client: NewClient(settings.apiKey),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -19,7 +19,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
dateFormat: settings.dateFormat,
|
dateFormat: settings.dateFormat,
|
||||||
|
@ -20,7 +20,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
args: settings.args,
|
args: settings.args,
|
||||||
cmd: settings.cmd,
|
cmd: settings.cmd,
|
||||||
|
@ -27,7 +27,7 @@ type Widget struct {
|
|||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
summaryList: summaryList{},
|
summaryList: summaryList{},
|
||||||
|
@ -20,7 +20,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
device_token: settings.deviceToken,
|
device_token: settings.deviceToken,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -22,7 +22,7 @@ type Widget struct {
|
|||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
priceWidget: price.NewWidget(settings.priceSettings),
|
priceWidget: price.NewWidget(settings.priceSettings),
|
||||||
toplistWidget: toplist.NewWidget(settings.toplistSettings),
|
toplistWidget: toplist.NewWidget(settings.toplistSettings),
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
ch: make(chan struct{}),
|
ch: make(chan struct{}),
|
||||||
|
@ -49,7 +49,7 @@ var (
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -42,8 +42,8 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget("git", "repository", "repositories"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "repository", "repositories"),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
pages: pages,
|
pages: pages,
|
||||||
|
@ -32,7 +32,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -39,7 +39,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
|
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
gitlab: gitlab,
|
gitlab: gitlab,
|
||||||
|
@ -32,7 +32,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ type ipinfo struct {
|
|||||||
// NewWidget constructor
|
// NewWidget constructor
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ type ipinfo struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "repository", "repositories"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "repository", "repositories"),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
pages: pages,
|
pages: pages,
|
||||||
|
@ -33,7 +33,7 @@ var offset = 0
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
Battery: NewBattery(),
|
Battery: NewBattery(),
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -35,7 +35,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,16 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
spotifyClient := spotigopher.NewClient()
|
spotifyClient := spotigopher.NewClient()
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Info: spotigopher.Info{},
|
Info: spotigopher.Info{},
|
||||||
SpotifyClient: spotifyClient,
|
SpotifyClient: spotifyClient,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.settings.common.RefreshInterval = 5
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
widget.TextWidget.RefreshInt = 5
|
|
||||||
widget.View.SetInputCapture(widget.captureInput)
|
widget.View.SetInputCapture(widget.captureInput)
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
widget.View.SetWordWrap(true)
|
widget.View.SetWordWrap(true)
|
||||||
|
@ -93,7 +93,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
|
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Info: Info{},
|
Info: Info{},
|
||||||
client: client,
|
client: client,
|
||||||
@ -135,8 +135,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
// If inconvenient, I'll remove this option and save the URL in a file or some other method.
|
// If inconvenient, I'll remove this option and save the URL in a file or some other method.
|
||||||
wtf.OpenFile(`"` + authURL + `"`)
|
wtf.OpenFile(`"` + authURL + `"`)
|
||||||
|
|
||||||
|
widget.settings.common.RefreshInterval = 5
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
widget.TextWidget.RefreshInt = 5
|
|
||||||
widget.View.SetInputCapture(widget.captureInput)
|
widget.View.SetInputCapture(widget.captureInput)
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
widget.View.SetWordWrap(true)
|
widget.View.SetWordWrap(true)
|
||||||
|
@ -14,7 +14,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
CurrentIcon: 0,
|
CurrentIcon: 0,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -19,7 +19,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, date, version string, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, date, version string, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
Date: date,
|
Date: date,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -42,19 +42,17 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "filePath", "filePaths"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "filePath", "filePaths"),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use a timer for this widget, watch for filesystem changes instead
|
// Don't use a timer for this widget, watch for filesystem changes instead
|
||||||
widget.RefreshInt = 0
|
widget.settings.common.RefreshInterval = 0
|
||||||
|
|
||||||
widget.LoadSources()
|
|
||||||
widget.SetDisplayFunction(widget.display)
|
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
|
widget.LoadSources()
|
||||||
|
widget.SetDisplayFunction(widget.display)
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
widget.View.SetWordWrap(true)
|
widget.View.SetWordWrap(true)
|
||||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
@ -49,7 +49,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -37,7 +37,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "screenName", "screenNames"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "screenName", "screenNames"),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
idx: 0,
|
idx: 0,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -15,7 +15,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, name string, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, name string, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, name, name, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ type Widget struct {
|
|||||||
// NewWidget creates a new widget
|
// NewWidget creates a new widget
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetScrollable(true)
|
widget.View.SetScrollable(true)
|
||||||
|
@ -18,7 +18,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, false),
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
@ -19,7 +19,7 @@ type Widget struct {
|
|||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common.Name, settings.common.ConfigKey, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
@ -5,44 +5,49 @@ import (
|
|||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config *config.Config
|
var Config *config.Config
|
||||||
|
|
||||||
type TextWidget struct {
|
type TextWidget struct {
|
||||||
enabled bool
|
enabled bool
|
||||||
focusable bool
|
focusable bool
|
||||||
focusChar string
|
focusChar string
|
||||||
key string
|
key string
|
||||||
name string
|
name string
|
||||||
|
refreshInterval int
|
||||||
|
|
||||||
RefreshInt int
|
View *tview.TextView
|
||||||
View *tview.TextView
|
|
||||||
|
|
||||||
|
CommonSettings *cfg.Common
|
||||||
Position
|
Position
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextWidget(app *tview.Application, name string, configKey string, focusable bool) TextWidget {
|
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
|
||||||
focusCharValue := Config.UInt(fmt.Sprintf("wtf.mods.%s.focusChar", configKey), -1)
|
configKey := commonSettings.ConfigKey
|
||||||
focusChar := string('0' + focusCharValue)
|
|
||||||
if focusCharValue == -1 {
|
focusChar := string('0' + commonSettings.FocusChar)
|
||||||
|
if commonSettings.FocusChar == -1 {
|
||||||
focusChar = ""
|
focusChar = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
widget := TextWidget{
|
widget := TextWidget{
|
||||||
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
CommonSettings: commonSettings,
|
||||||
focusable: focusable,
|
|
||||||
focusChar: focusChar,
|
enabled: commonSettings.Enabled,
|
||||||
key: configKey,
|
focusable: focusable,
|
||||||
name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
|
focusChar: focusChar,
|
||||||
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
|
key: commonSettings.ConfigKey,
|
||||||
|
name: commonSettings.Name,
|
||||||
|
refreshInterval: commonSettings.RefreshInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Position = NewPosition(
|
widget.Position = NewPosition(
|
||||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
|
commonSettings.Position.Top,
|
||||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
|
commonSettings.Position.Left,
|
||||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
|
commonSettings.Position.Width,
|
||||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
|
commonSettings.Position.Height,
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.addView(app, configKey)
|
widget.addView(app, configKey)
|
||||||
@ -54,10 +59,10 @@ func NewTextWidget(app *tview.Application, name string, configKey string, focusa
|
|||||||
|
|
||||||
func (widget *TextWidget) BorderColor() string {
|
func (widget *TextWidget) BorderColor() string {
|
||||||
if widget.Focusable() {
|
if widget.Focusable() {
|
||||||
return Config.UString("wtf.colors.border.focusable", "red")
|
return widget.CommonSettings.Colors.BorderFocusable
|
||||||
}
|
}
|
||||||
|
|
||||||
return Config.UString("wtf.colors.border.normal", "gray")
|
return widget.CommonSettings.Colors.BorderNormal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *TextWidget) ContextualTitle(defaultStr string) string {
|
func (widget *TextWidget) ContextualTitle(defaultStr string) string {
|
||||||
@ -103,7 +108,7 @@ func (widget *TextWidget) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *TextWidget) RefreshInterval() int {
|
func (widget *TextWidget) RefreshInterval() int {
|
||||||
return widget.RefreshInt
|
return widget.refreshInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *TextWidget) SetFocusChar(char string) {
|
func (widget *TextWidget) SetFocusChar(char string) {
|
||||||
@ -119,34 +124,19 @@ func (widget *TextWidget) TextView() *tview.TextView {
|
|||||||
func (widget *TextWidget) addView(app *tview.Application, configKey string) {
|
func (widget *TextWidget) addView(app *tview.Application, configKey string) {
|
||||||
view := tview.NewTextView()
|
view := tview.NewTextView()
|
||||||
|
|
||||||
view.SetBackgroundColor(ColorFor(
|
view.SetBackgroundColor(ColorFor(widget.CommonSettings.Colors.Background))
|
||||||
Config.UString(fmt.Sprintf("wtf.mods.%s.colors.background", configKey),
|
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
||||||
Config.UString("wtf.colors.background", "black"),
|
view.SetTextColor(ColorFor(widget.CommonSettings.Colors.Text))
|
||||||
),
|
view.SetTitleColor(ColorFor(widget.CommonSettings.Colors.Title))
|
||||||
))
|
|
||||||
|
|
||||||
view.SetTextColor(ColorFor(
|
|
||||||
Config.UString(
|
|
||||||
fmt.Sprintf("wtf.mods.%s.colors.text", configKey),
|
|
||||||
Config.UString("wtf.colors.text", "white"),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
view.SetTitleColor(ColorFor(
|
|
||||||
Config.UString(
|
|
||||||
fmt.Sprintf("wtf.mods.%s.colors.title", configKey),
|
|
||||||
Config.UString("wtf.colors.title", "white"),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
view.SetBorder(true)
|
view.SetBorder(true)
|
||||||
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
|
||||||
view.SetChangedFunc(func() {
|
|
||||||
app.Draw()
|
|
||||||
})
|
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.ContextualTitle(widget.name))
|
view.SetTitle(widget.ContextualTitle(widget.name))
|
||||||
view.SetWrap(false)
|
view.SetWrap(false)
|
||||||
|
|
||||||
|
view.SetChangedFunc(func() {
|
||||||
|
app.Draw()
|
||||||
|
})
|
||||||
|
|
||||||
widget.View = view
|
widget.View = view
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
//"sync"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
21
wtf/widget_validator.go
Normal file
21
wtf/widget_validator.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package wtf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check that all the loaded widgets are valid for display
|
||||||
|
func ValidateWidgets(widgets []Wtfable) (bool, error) {
|
||||||
|
result := true
|
||||||
|
var err error
|
||||||
|
|
||||||
|
for _, widget := range widgets {
|
||||||
|
if widget.Enabled() && !widget.IsPositionable() {
|
||||||
|
errStr := fmt.Sprintf("Widget config has invalid values: %s", widget.Key())
|
||||||
|
log.Fatalln(errStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, err
|
||||||
|
}
|
@ -9,15 +9,15 @@ type Wtfable interface {
|
|||||||
Scheduler
|
Scheduler
|
||||||
|
|
||||||
BorderColor() string
|
BorderColor() string
|
||||||
Focusable() bool
|
|
||||||
FocusChar() string
|
FocusChar() string
|
||||||
|
Focusable() bool
|
||||||
Key() string
|
Key() string
|
||||||
Name() string
|
Name() string
|
||||||
SetFocusChar(string)
|
SetFocusChar(string)
|
||||||
TextView() *tview.TextView
|
TextView() *tview.TextView
|
||||||
|
|
||||||
Top() int
|
|
||||||
Left() int
|
|
||||||
Width() int
|
|
||||||
Height() int
|
Height() int
|
||||||
|
Left() int
|
||||||
|
Top() int
|
||||||
|
Width() int
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
. "github.com/wtfutil/wtf/wtf"
|
. "github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestASCIItoTviewColors(t *testing.T) {
|
func Test_ASCIItoTviewColors(t *testing.T) {
|
||||||
Equal(t, "", ASCIItoTviewColors(""))
|
Equal(t, "", ASCIItoTviewColors(""))
|
||||||
Equal(t, "cat", ASCIItoTviewColors("cat"))
|
Equal(t, "cat", ASCIItoTviewColors("cat"))
|
||||||
Equal(t, "[38;5;226mcat/[-]", ASCIItoTviewColors("[38;5;226mcat/[0m"))
|
Equal(t, "[38;5;226mcat/[-]", ASCIItoTviewColors("[38;5;226mcat/[0m"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user