diff --git a/status/widget.go b/status/widget.go index 1845f036..ba056c95 100644 --- a/status/widget.go +++ b/status/widget.go @@ -39,10 +39,12 @@ func (widget *Widget) Refresh() { widget.RefreshedAt = time.Now() + _, _, w, _ := widget.View.GetInnerRect() + widget.View.Clear() fmt.Fprintf( widget.View, - "%107s\n%123s", + fmt.Sprintf("%%%ds\n%%%ds", w-2, w-1), widget.animation(), widget.timezones(), ) @@ -86,5 +88,5 @@ func (widget *Widget) timezones() string { formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat)) } - return strings.Join(formattedTimes, " [yellow]•[white] ") + return strings.Join(formattedTimes, " • ") } diff --git a/wtf.go b/wtf.go index 5ac1f23b..da6940f0 100644 --- a/wtf.go +++ b/wtf.go @@ -1,7 +1,6 @@ package main import ( - //"fmt" "os" "time" @@ -20,7 +19,7 @@ import ( "github.com/senorprogrammer/wtf/wtf" ) -func addToApp(grid *tview.Grid, widget wtf.TextViewer) { +func addToGrid(grid *tview.Grid, widget wtf.TextViewer) { if widget.Disabled() { return } @@ -37,6 +36,16 @@ func addToApp(grid *tview.Grid, widget wtf.TextViewer) { ) } +// Grid stores all the widgets onscreen (like an HTML table) +func buildGrid() *tview.Grid { + grid := tview.NewGrid() + grid.SetColumns(wtf.ToInts(Config.UList("wtf.grid.columns"))...) + grid.SetRows(wtf.ToInts(Config.UList("wtf.grid.rows"))...) + grid.SetBorder(false) + + return grid +} + func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { // Ctrl-R: force-refreshes every widget if event.Key() == tcell.KeyCtrlR { @@ -73,52 +82,36 @@ var Modules []wtf.TextViewer func main() { wtf.Config = Config - // Grid stores all the widgets onscreen (like an HTML table) - grid := tview.NewGrid() - grid.SetColumns(wtf.ToInts(Config.UList("wtf.grid.columns"))...) - grid.SetRows(wtf.ToInts(Config.UList("wtf.grid.rows"))...) - grid.SetBorder(false) - // TODO: Really need to generalize all of these. This don't scale bamboohr.Config = Config bamboo := bamboohr.NewWidget() - go wtf.Schedule(bamboo) gcal.Config = Config cal := gcal.NewWidget() - go wtf.Schedule(cal) git.Config = Config git := git.NewWidget() - go wtf.Schedule(git) github.Config = Config github := github.NewWidget() - go wtf.Schedule(github) jira.Config = Config jira := jira.NewWidget() - go wtf.Schedule(jira) newrelic.Config = Config newrelic := newrelic.NewWidget() - go wtf.Schedule(newrelic) opsgenie.Config = Config opsgenie := opsgenie.NewWidget() - go wtf.Schedule(opsgenie) security.Config = Config sec := security.NewWidget() - go wtf.Schedule(sec) status.Config = Config stat := status.NewWidget() - go wtf.Schedule(stat) weather.Config = Config weather := weather.NewWidget() - go wtf.Schedule(weather) Modules = []wtf.TextViewer{ bamboo, @@ -133,8 +126,11 @@ func main() { weather, } + grid := buildGrid() + for _, module := range Modules { - addToApp(grid, module) + addToGrid(grid, module) + go wtf.Schedule(module) } app := tview.NewApplication() diff --git a/wtf/text_viewer.go b/wtf/text_viewer.go index f8fe1bc8..70839e9d 100644 --- a/wtf/text_viewer.go +++ b/wtf/text_viewer.go @@ -4,10 +4,12 @@ import ( "github.com/rivo/tview" ) +// TODO: I really need to come up with a better name for this now type TextViewer interface { Enabler + Scheduler - Refresh() + //Refresh() TextView() *tview.TextView Top() int