1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Don't display disabled widgets

This commit is contained in:
Chris Cummer 2018-04-07 14:36:13 -07:00 committed by Chris Cummer
parent ae13d52665
commit 79bc8216d6
13 changed files with 61 additions and 22 deletions

View File

@ -29,7 +29,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -31,7 +31,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -31,7 +31,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -30,7 +30,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -29,7 +29,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -30,7 +30,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -30,7 +30,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -30,7 +30,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -32,7 +32,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

View File

@ -31,7 +31,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.Enabled == false { if widget.Disabled() {
return return
} }

39
wtf.go
View File

@ -32,6 +32,14 @@ func refresher(stat *status.Widget, app *tview.Application) {
} }
} }
func addToApp(grid *tview.Grid, widget wtf.TextViewer) {
if widget.Disabled() {
return
}
grid.AddItem(widget.TextView(), 0, 0, 2, 1, 0, 0, false)
}
var result = wtf.CreateConfigDir() var result = wtf.CreateConfigDir()
var Config = wtf.LoadConfigFile() var Config = wtf.LoadConfigFile()
@ -85,16 +93,27 @@ func main() {
grid.SetColumns(37, 37, 37, 37, 37) // How _wide_ the column is, in terminal columns grid.SetColumns(37, 37, 37, 37, 37) // How _wide_ the column is, in terminal columns
grid.SetBorder(false) grid.SetBorder(false)
grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, false) addToApp(grid, bamboo)
grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false) addToApp(grid, cal)
grid.AddItem(git.View, 0, 2, 2, 3, 0, 0, false) addToApp(grid, git)
grid.AddItem(github.View, 2, 2, 2, 3, 0, 0, false) addToApp(grid, github)
grid.AddItem(newrelic.View, 4, 2, 1, 3, 0, 0, false) addToApp(grid, newrelic)
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false) addToApp(grid, weather)
grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false) addToApp(grid, sec)
grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false) addToApp(grid, opsgenie)
grid.AddItem(jira.View, 1, 1, 1, 1, 0, 0, false) addToApp(grid, jira)
grid.AddItem(stat.View, 5, 2, 3, 3, 0, 0, false) addToApp(grid, stat)
//grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, false)
//grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false)
//grid.AddItem(git.View, 0, 2, 2, 3, 0, 0, false)
//grid.AddItem(github.View, 2, 2, 2, 3, 0, 0, false)
//grid.AddItem(newrelic.View, 4, 2, 1, 3, 0, 0, false)
//grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
//grid.AddItem(sec.View, 5, 0, 1, 1, 0, 0, false)
//grid.AddItem(opsgenie.View, 2, 0, 2, 1, 0, 0, false)
//grid.AddItem(jira.View, 1, 1, 1, 1, 0, 0, false)
//grid.AddItem(stat.View, 5, 2, 3, 3, 0, 0, false)
app := tview.NewApplication() app := tview.NewApplication()

11
wtf/text_viewer.go Normal file
View File

@ -0,0 +1,11 @@
package wtf
import (
"github.com/rivo/tview"
)
type TextViewer interface {
Disabled() bool
Enabled() bool
TextView() *tview.TextView
}

View File

@ -18,7 +18,8 @@ type Position struct {
} }
type TextWidget struct { type TextWidget struct {
Enabled bool enabled bool
Name string Name string
Position Position Position Position
RefreshedAt time.Time RefreshedAt time.Time
@ -28,7 +29,7 @@ type TextWidget struct {
func NewTextWidget(name string, configKey string) TextWidget { func NewTextWidget(name string, configKey string) TextWidget {
widget := TextWidget{ widget := TextWidget{
Enabled: Config.UBool(fmt.Sprintf("wtf.%s.enabled", configKey), false), enabled: Config.UBool(fmt.Sprintf("wtf.%s.enabled", configKey), false),
Name: name, Name: name,
RefreshInt: Config.UInt(fmt.Sprintf("wtf.%s.refreshInterval", configKey)), RefreshInt: Config.UInt(fmt.Sprintf("wtf.%s.refreshInterval", configKey)),
} }
@ -38,6 +39,14 @@ func NewTextWidget(name string, configKey string) TextWidget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) Disabled() bool {
return !widget.Enabled()
}
func (widget *TextWidget) Enabled() bool {
return widget.enabled
}
func (widget *TextWidget) RefreshInterval() int { func (widget *TextWidget) RefreshInterval() int {
return widget.RefreshInt return widget.RefreshInt
} }