mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Get rid of the rest of global config
Pass appropriate config to display/focus tracker Move open file command to a singular global Remove global config variable
This commit is contained in:
parent
2d7cafa3bf
commit
ce2a9b3301
@ -17,8 +17,6 @@ const ConfigDirV1 = "~/.wtf/"
|
||||
// ConfigDirV2 defines the path to the second version of the configuration. Use this.
|
||||
const ConfigDirV2 = "~/.config/wtf/"
|
||||
|
||||
var Config *config.Config
|
||||
|
||||
/* -------------------- Config Migration -------------------- */
|
||||
|
||||
// MigrateOldConfig copies any existing configuration from the old location
|
||||
@ -132,7 +130,6 @@ func LoadConfigFile(filePath string) *config.Config {
|
||||
fmt.Printf(" %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
Config = cfg
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
10
main.go
10
main.go
@ -86,9 +86,9 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
||||
wtf.ValidateWidgets(widgets)
|
||||
runningWidgets = widgets
|
||||
|
||||
focusTracker = wtf.NewFocusTracker(app, widgets)
|
||||
focusTracker = wtf.NewFocusTracker(app, widgets, config)
|
||||
|
||||
display := wtf.NewDisplay(widgets)
|
||||
display := wtf.NewDisplay(widgets, config)
|
||||
pages.AddPage("grid", display.Grid, true, true)
|
||||
case err := <-watch.Error:
|
||||
log.Fatalln(err)
|
||||
@ -132,6 +132,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
wtf.OpenFileUtil = config.UString("wtf.openFileUtil", "open")
|
||||
|
||||
app := tview.NewApplication()
|
||||
pages := tview.NewPages()
|
||||
|
||||
@ -139,9 +141,9 @@ func main() {
|
||||
wtf.ValidateWidgets(widgets)
|
||||
runningWidgets = widgets
|
||||
|
||||
focusTracker = wtf.NewFocusTracker(app, widgets)
|
||||
focusTracker = wtf.NewFocusTracker(app, widgets, config)
|
||||
|
||||
display := wtf.NewDisplay(widgets)
|
||||
display := wtf.NewDisplay(widgets, config)
|
||||
pages.AddPage("grid", display.Grid, true, true)
|
||||
|
||||
app.SetInputCapture(keyboardIntercept)
|
||||
|
@ -1,21 +1,23 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type Display struct {
|
||||
Grid *tview.Grid
|
||||
Grid *tview.Grid
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
func NewDisplay(widgets []Wtfable) *Display {
|
||||
func NewDisplay(widgets []Wtfable, config *config.Config) *Display {
|
||||
display := Display{
|
||||
Grid: tview.NewGrid(),
|
||||
Grid: tview.NewGrid(),
|
||||
config: config,
|
||||
}
|
||||
|
||||
display.build(widgets)
|
||||
display.Grid.SetBackgroundColor(ColorFor(cfg.Config.UString("wtf.colors.background", "black")))
|
||||
display.Grid.SetBackgroundColor(ColorFor(config.UString("wtf.colors.background", "black")))
|
||||
|
||||
return &display
|
||||
}
|
||||
@ -44,8 +46,8 @@ func (display *Display) add(widget Wtfable) {
|
||||
}
|
||||
|
||||
func (display *Display) build(widgets []Wtfable) *tview.Grid {
|
||||
display.Grid.SetColumns(ToInts(cfg.Config.UList("wtf.grid.columns"))...)
|
||||
display.Grid.SetRows(ToInts(cfg.Config.UList("wtf.grid.rows"))...)
|
||||
display.Grid.SetColumns(ToInts(display.config.UList("wtf.grid.columns"))...)
|
||||
display.Grid.SetRows(ToInts(display.config.UList("wtf.grid.rows"))...)
|
||||
display.Grid.SetBorder(false)
|
||||
|
||||
for _, widget := range widgets {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type FocusState int
|
||||
@ -19,13 +19,15 @@ type FocusTracker struct {
|
||||
App *tview.Application
|
||||
Idx int
|
||||
Widgets []Wtfable
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
func NewFocusTracker(app *tview.Application, widgets []Wtfable) FocusTracker {
|
||||
func NewFocusTracker(app *tview.Application, widgets []Wtfable, config *config.Config) FocusTracker {
|
||||
focusTracker := FocusTracker{
|
||||
App: app,
|
||||
Idx: -1,
|
||||
Widgets: widgets,
|
||||
config: config,
|
||||
}
|
||||
|
||||
focusTracker.assignHotKeys()
|
||||
@ -162,7 +164,7 @@ func (tracker *FocusTracker) focus(idx int) {
|
||||
}
|
||||
|
||||
view := widget.TextView()
|
||||
view.SetBorderColor(ColorFor(cfg.Config.UString("wtf.colors.border.focused", "gray")))
|
||||
view.SetBorderColor(ColorFor(tracker.config.UString("wtf.colors.border.focused", "gray")))
|
||||
tracker.App.SetFocus(view)
|
||||
}
|
||||
|
||||
@ -209,5 +211,5 @@ func (tracker *FocusTracker) increment() {
|
||||
}
|
||||
|
||||
func (tracker *FocusTracker) useNavShortcuts() bool {
|
||||
return cfg.Config.UBool("wtf.navigation.shortcuts", true)
|
||||
return tracker.config.UBool("wtf.navigation.shortcuts", true)
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
const SimpleDateFormat = "Jan 2"
|
||||
@ -19,6 +17,8 @@ const FriendlyDateFormat = "Mon, Jan 2"
|
||||
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
||||
const TimestampFormat = "2006-01-02T15:04:05-0700"
|
||||
|
||||
var OpenFileUtil = "open"
|
||||
|
||||
func CenterText(str string, width int) string {
|
||||
if width < 0 {
|
||||
width = 0
|
||||
@ -93,8 +93,7 @@ func OpenFile(path string) {
|
||||
}
|
||||
} else {
|
||||
filePath, _ := ExpandHomeDir(path)
|
||||
openFileUtil := cfg.Config.UString("wtf.openFileUtil", "open")
|
||||
cmd := exec.Command(openFileUtil, filePath)
|
||||
cmd := exec.Command(OpenFileUtil, filePath)
|
||||
ExecuteCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user