mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Extract most app setup out of main and into wtf_app
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type Display struct {
|
||||
Grid *tview.Grid
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
func NewDisplay(widgets []Wtfable, config *config.Config) *Display {
|
||||
display := Display{
|
||||
Grid: tview.NewGrid(),
|
||||
config: config,
|
||||
}
|
||||
|
||||
display.build(widgets)
|
||||
display.Grid.SetBackgroundColor(ColorFor(config.UString("wtf.colors.background", "black")))
|
||||
|
||||
return &display
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (display *Display) add(widget Wtfable) {
|
||||
if widget.Disabled() {
|
||||
return
|
||||
}
|
||||
|
||||
display.Grid.AddItem(
|
||||
widget.TextView(),
|
||||
widget.CommonSettings().Top,
|
||||
widget.CommonSettings().Left,
|
||||
widget.CommonSettings().Height,
|
||||
widget.CommonSettings().Width,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
func (display *Display) build(widgets []Wtfable) *tview.Grid {
|
||||
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 {
|
||||
display.add(widget)
|
||||
go Schedule(widget)
|
||||
}
|
||||
|
||||
return display.Grid
|
||||
}
|
||||
Reference in New Issue
Block a user