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.
|
// ConfigDirV2 defines the path to the second version of the configuration. Use this.
|
||||||
const ConfigDirV2 = "~/.config/wtf/"
|
const ConfigDirV2 = "~/.config/wtf/"
|
||||||
|
|
||||||
var Config *config.Config
|
|
||||||
|
|
||||||
/* -------------------- Config Migration -------------------- */
|
/* -------------------- Config Migration -------------------- */
|
||||||
|
|
||||||
// MigrateOldConfig copies any existing configuration from the old location
|
// 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())
|
fmt.Printf(" %s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
Config = cfg
|
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
10
main.go
10
main.go
@ -86,9 +86,9 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
|||||||
wtf.ValidateWidgets(widgets)
|
wtf.ValidateWidgets(widgets)
|
||||||
runningWidgets = 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)
|
pages.AddPage("grid", display.Grid, true, true)
|
||||||
case err := <-watch.Error:
|
case err := <-watch.Error:
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
@ -132,6 +132,8 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wtf.OpenFileUtil = config.UString("wtf.openFileUtil", "open")
|
||||||
|
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
pages := tview.NewPages()
|
pages := tview.NewPages()
|
||||||
|
|
||||||
@ -139,9 +141,9 @@ func main() {
|
|||||||
wtf.ValidateWidgets(widgets)
|
wtf.ValidateWidgets(widgets)
|
||||||
runningWidgets = 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)
|
pages.AddPage("grid", display.Grid, true, true)
|
||||||
|
|
||||||
app.SetInputCapture(keyboardIntercept)
|
app.SetInputCapture(keyboardIntercept)
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
package wtf
|
package wtf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Display struct {
|
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{
|
display := Display{
|
||||||
Grid: tview.NewGrid(),
|
Grid: tview.NewGrid(),
|
||||||
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
display.build(widgets)
|
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
|
return &display
|
||||||
}
|
}
|
||||||
@ -44,8 +46,8 @@ func (display *Display) add(widget Wtfable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (display *Display) build(widgets []Wtfable) *tview.Grid {
|
func (display *Display) build(widgets []Wtfable) *tview.Grid {
|
||||||
display.Grid.SetColumns(ToInts(cfg.Config.UList("wtf.grid.columns"))...)
|
display.Grid.SetColumns(ToInts(display.config.UList("wtf.grid.columns"))...)
|
||||||
display.Grid.SetRows(ToInts(cfg.Config.UList("wtf.grid.rows"))...)
|
display.Grid.SetRows(ToInts(display.config.UList("wtf.grid.rows"))...)
|
||||||
display.Grid.SetBorder(false)
|
display.Grid.SetBorder(false)
|
||||||
|
|
||||||
for _, widget := range widgets {
|
for _, widget := range widgets {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package wtf
|
package wtf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FocusState int
|
type FocusState int
|
||||||
@ -19,13 +19,15 @@ type FocusTracker struct {
|
|||||||
App *tview.Application
|
App *tview.Application
|
||||||
Idx int
|
Idx int
|
||||||
Widgets []Wtfable
|
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{
|
focusTracker := FocusTracker{
|
||||||
App: app,
|
App: app,
|
||||||
Idx: -1,
|
Idx: -1,
|
||||||
Widgets: widgets,
|
Widgets: widgets,
|
||||||
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTracker.assignHotKeys()
|
focusTracker.assignHotKeys()
|
||||||
@ -162,7 +164,7 @@ func (tracker *FocusTracker) focus(idx int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
view := widget.TextView()
|
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)
|
tracker.App.SetFocus(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,5 +211,5 @@ func (tracker *FocusTracker) increment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) useNavShortcuts() bool {
|
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"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/cfg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const SimpleDateFormat = "Jan 2"
|
const SimpleDateFormat = "Jan 2"
|
||||||
@ -19,6 +17,8 @@ const FriendlyDateFormat = "Mon, Jan 2"
|
|||||||
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
||||||
const TimestampFormat = "2006-01-02T15:04:05-0700"
|
const TimestampFormat = "2006-01-02T15:04:05-0700"
|
||||||
|
|
||||||
|
var OpenFileUtil = "open"
|
||||||
|
|
||||||
func CenterText(str string, width int) string {
|
func CenterText(str string, width int) string {
|
||||||
if width < 0 {
|
if width < 0 {
|
||||||
width = 0
|
width = 0
|
||||||
@ -93,8 +93,7 @@ func OpenFile(path string) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filePath, _ := ExpandHomeDir(path)
|
filePath, _ := ExpandHomeDir(path)
|
||||||
openFileUtil := cfg.Config.UString("wtf.openFileUtil", "open")
|
cmd := exec.Command(OpenFileUtil, filePath)
|
||||||
cmd := exec.Command(openFileUtil, filePath)
|
|
||||||
ExecuteCommand(cmd)
|
ExecuteCommand(cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user