mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Move the FocusTracker from /wtf to /app
This commit is contained in:
parent
8436b74ac1
commit
b790b27000
@ -1,10 +1,11 @@
|
|||||||
package wtf
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FocusState int
|
type FocusState int
|
||||||
@ -21,12 +22,12 @@ type FocusTracker struct {
|
|||||||
App *tview.Application
|
App *tview.Application
|
||||||
Idx int
|
Idx int
|
||||||
IsFocused bool
|
IsFocused bool
|
||||||
Widgets []Wtfable
|
Widgets []wtf.Wtfable
|
||||||
|
|
||||||
config *config.Config
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFocusTracker(app *tview.Application, widgets []Wtfable, config *config.Config) FocusTracker {
|
func NewFocusTracker(app *tview.Application, widgets []wtf.Wtfable, config *config.Config) FocusTracker {
|
||||||
focusTracker := FocusTracker{
|
focusTracker := FocusTracker{
|
||||||
App: app,
|
App: app,
|
||||||
Idx: -1,
|
Idx: -1,
|
||||||
@ -157,7 +158,7 @@ func (tracker *FocusTracker) blur(idx int) {
|
|||||||
view := widget.TextView()
|
view := widget.TextView()
|
||||||
view.Blur()
|
view.Blur()
|
||||||
|
|
||||||
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
view.SetBorderColor(wtf.ColorFor(widget.BorderColor()))
|
||||||
|
|
||||||
tracker.IsFocused = false
|
tracker.IsFocused = false
|
||||||
}
|
}
|
||||||
@ -177,12 +178,12 @@ func (tracker *FocusTracker) focus(idx int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
view := widget.TextView()
|
view := widget.TextView()
|
||||||
view.SetBorderColor(ColorFor(tracker.config.UString("wtf.colors.border.focused", "gray")))
|
view.SetBorderColor(wtf.ColorFor(tracker.config.UString("wtf.colors.border.focused", "gray")))
|
||||||
tracker.App.SetFocus(view)
|
tracker.App.SetFocus(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) focusables() []Wtfable {
|
func (tracker *FocusTracker) focusables() []wtf.Wtfable {
|
||||||
focusable := []Wtfable{}
|
focusable := []wtf.Wtfable{}
|
||||||
|
|
||||||
for _, widget := range tracker.Widgets {
|
for _, widget := range tracker.Widgets {
|
||||||
if widget.Focusable() {
|
if widget.Focusable() {
|
||||||
@ -207,7 +208,7 @@ func (tracker *FocusTracker) focusables() []Wtfable {
|
|||||||
return focusable
|
return focusable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracker *FocusTracker) focusableAt(idx int) Wtfable {
|
func (tracker *FocusTracker) focusableAt(idx int) wtf.Wtfable {
|
||||||
if idx < 0 || idx >= len(tracker.focusables()) {
|
if idx < 0 || idx >= len(tracker.focusables()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ type WtfApp struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
configFilePath string
|
configFilePath string
|
||||||
display *Display
|
display *Display
|
||||||
focusTracker wtf.FocusTracker
|
focusTracker FocusTracker
|
||||||
isCustomConfig bool
|
isCustomConfig bool
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
widgets []wtf.Wtfable
|
widgets []wtf.Wtfable
|
||||||
@ -39,7 +39,7 @@ func NewWtfApp(app *tview.Application, config *config.Config, configFilePath str
|
|||||||
|
|
||||||
wtfApp.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config)
|
wtfApp.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config)
|
||||||
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
||||||
wtfApp.focusTracker = wtf.NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config)
|
wtfApp.focusTracker = NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config)
|
||||||
|
|
||||||
wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true)
|
wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true)
|
||||||
wtfApp.app.SetRoot(wtfApp.pages, true)
|
wtfApp.app.SetRoot(wtfApp.pages, true)
|
||||||
|
2
main.go
2
main.go
@ -69,7 +69,7 @@ func main() {
|
|||||||
wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, flags.HasCustomConfig())
|
wtfApp := app.NewWtfApp(tviewApp, config, flags.Config, flags.HasCustomConfig())
|
||||||
wtfApp.Start()
|
wtfApp.Start()
|
||||||
|
|
||||||
if err := wtfApp.App().Run(); err != nil {
|
if err := tviewApp.Run(); err != nil {
|
||||||
fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err)
|
fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user