mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Further reduce usage of global
Bargraph moves to common settings "Global" config moves out of wtf and into cfg for the few things that need it We can probably eliminate a global config used across things if we want to
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
//BarGraph lets make graphs
|
||||
@@ -19,6 +20,7 @@ type BarGraph struct {
|
||||
|
||||
RefreshInt int
|
||||
View *tview.TextView
|
||||
settings *cfg.Common
|
||||
|
||||
Position
|
||||
}
|
||||
@@ -30,25 +32,25 @@ type Bar struct {
|
||||
}
|
||||
|
||||
// NewBarGraph initialize your fancy new graph
|
||||
func NewBarGraph(app *tview.Application, name string, configKey string, focusable bool) BarGraph {
|
||||
func NewBarGraph(app *tview.Application, name string, settings *cfg.Common, focusable bool) BarGraph {
|
||||
widget := BarGraph{
|
||||
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
||||
enabled: settings.Enabled,
|
||||
focusable: focusable,
|
||||
key: configKey,
|
||||
maxStars: Config.UInt(fmt.Sprintf("wtf.mods.%s.graphStars", configKey), 20),
|
||||
name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
|
||||
starChar: Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), "|"),
|
||||
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey), 1),
|
||||
maxStars: settings.Config.UInt("graphStars", 20),
|
||||
name: settings.Title,
|
||||
starChar: settings.Config.UString("graphIcon", "|"),
|
||||
RefreshInt: settings.RefreshInterval,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.Position = NewPosition(
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.top", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.left", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.width", configKey)),
|
||||
Config.UInt(fmt.Sprintf("wtf.mods.%s.position.height", configKey)),
|
||||
settings.Position.Top,
|
||||
settings.Position.Left,
|
||||
settings.Position.Width,
|
||||
settings.Position.Height,
|
||||
)
|
||||
|
||||
widget.View = widget.addView(configKey)
|
||||
widget.View = widget.addView()
|
||||
widget.View.SetChangedFunc(func() {
|
||||
app.Draw()
|
||||
})
|
||||
@@ -58,10 +60,10 @@ func NewBarGraph(app *tview.Application, name string, configKey string, focusabl
|
||||
|
||||
func (widget *BarGraph) BorderColor() string {
|
||||
if widget.Focusable() {
|
||||
return Config.UString("wtf.colors.border.focusable", "red")
|
||||
return widget.settings.Colors.BorderFocusable
|
||||
}
|
||||
|
||||
return Config.UString("wtf.colors.border.normal", "gray")
|
||||
return widget.settings.Colors.BorderNormal
|
||||
}
|
||||
|
||||
func (widget *BarGraph) Disable() {
|
||||
@@ -112,20 +114,15 @@ func (widget *BarGraph) TextView() *tview.TextView {
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *BarGraph) addView(configKey string) *tview.TextView {
|
||||
func (widget *BarGraph) addView() *tview.TextView {
|
||||
view := tview.NewTextView()
|
||||
|
||||
view.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
|
||||
view.SetBackgroundColor(ColorFor(widget.settings.Colors.Background))
|
||||
view.SetBorder(true)
|
||||
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
||||
view.SetDynamicColors(true)
|
||||
view.SetTitle(widget.Name())
|
||||
view.SetTitleColor(ColorFor(
|
||||
Config.UString(
|
||||
fmt.Sprintf("wtf.mods.%s.colors.title", configKey),
|
||||
Config.UString("wtf.colors.title", "white"),
|
||||
),
|
||||
))
|
||||
view.SetTitleColor(ColorFor(widget.settings.Colors.Title))
|
||||
view.SetWrap(false)
|
||||
|
||||
return view
|
||||
|
||||
@@ -2,6 +2,7 @@ package wtf
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Display struct {
|
||||
@@ -14,7 +15,7 @@ func NewDisplay(widgets []Wtfable) *Display {
|
||||
}
|
||||
|
||||
display.build(widgets)
|
||||
display.Grid.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
|
||||
display.Grid.SetBackgroundColor(ColorFor(cfg.Config.UString("wtf.colors.background", "black")))
|
||||
|
||||
return &display
|
||||
}
|
||||
@@ -43,8 +44,8 @@ func (display *Display) add(widget Wtfable) {
|
||||
}
|
||||
|
||||
func (display *Display) build(widgets []Wtfable) *tview.Grid {
|
||||
display.Grid.SetColumns(ToInts(Config.UList("wtf.grid.columns"))...)
|
||||
display.Grid.SetRows(ToInts(Config.UList("wtf.grid.rows"))...)
|
||||
display.Grid.SetColumns(ToInts(cfg.Config.UList("wtf.grid.columns"))...)
|
||||
display.Grid.SetRows(ToInts(cfg.Config.UList("wtf.grid.rows"))...)
|
||||
display.Grid.SetBorder(false)
|
||||
|
||||
for _, widget := range widgets {
|
||||
|
||||
@@ -2,6 +2,7 @@ package wtf
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type FocusState int
|
||||
@@ -161,7 +162,7 @@ func (tracker *FocusTracker) focus(idx int) {
|
||||
}
|
||||
|
||||
view := widget.TextView()
|
||||
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focused", "gray")))
|
||||
view.SetBorderColor(ColorFor(cfg.Config.UString("wtf.colors.border.focused", "gray")))
|
||||
tracker.App.SetFocus(view)
|
||||
}
|
||||
|
||||
@@ -208,5 +209,5 @@ func (tracker *FocusTracker) increment() {
|
||||
}
|
||||
|
||||
func (tracker *FocusTracker) useNavShortcuts() bool {
|
||||
return Config.UBool("wtf.navigation.shortcuts", true)
|
||||
return cfg.Config.UBool("wtf.navigation.shortcuts", true)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package wtf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type MultiSourceWidget struct {
|
||||
@@ -38,8 +40,8 @@ func (widget *MultiSourceWidget) LoadSources() {
|
||||
s := fmt.Sprintf("wtf.mods.%s.%s", widget.module, widget.singular)
|
||||
p := fmt.Sprintf("wtf.mods.%s.%s", widget.module, widget.plural)
|
||||
|
||||
single := Config.UString(s, "")
|
||||
multiple := Config.UList(p, empty)
|
||||
single := cfg.Config.UString(s, "")
|
||||
multiple := cfg.Config.UList(p, empty)
|
||||
|
||||
asStrs := ToStrs(multiple)
|
||||
|
||||
|
||||
@@ -3,13 +3,10 @@ package wtf
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
var Config *config.Config
|
||||
|
||||
type TextWidget struct {
|
||||
enabled bool
|
||||
focusable bool
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
const SimpleDateFormat = "Jan 2"
|
||||
@@ -91,7 +93,7 @@ func OpenFile(path string) {
|
||||
}
|
||||
} else {
|
||||
filePath, _ := ExpandHomeDir(path)
|
||||
openFileUtil := Config.UString("wtf.openFileUtil", "open")
|
||||
openFileUtil := cfg.Config.UString("wtf.openFileUtil", "open")
|
||||
cmd := exec.Command(openFileUtil, filePath)
|
||||
ExecuteCommand(cmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user