mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Cleaner code around widget creation in wtf.go
This commit is contained in:
parent
31e17da358
commit
8e3287ba5c
@ -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, " • ")
|
||||
}
|
||||
|
34
wtf.go
34
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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user