From 9bda045ce1c1a32545cd44c052a78488700ea298 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 7 Apr 2018 23:36:05 -0700 Subject: [PATCH] Streamlining the widget creation process a bit more. Coords into config --- config.yml | 84 +++++++++++++++++++++++----------------------- wtf.go | 24 ++++++------- wtf/text_viewer.go | 4 +++ wtf/text_widget.go | 35 ++++++++++++++++--- 4 files changed, 88 insertions(+), 59 deletions(-) diff --git a/config.yml b/config.yml index 6ad02103..fc36790b 100644 --- a/config.yml +++ b/config.yml @@ -1,12 +1,12 @@ wtf: refreshInterval: 1 bamboohr: - enabled: false + enabled: true position: - top: - left: - width: - height: + top: 0 + left: 0 + height: 2 + width: 1 refreshInterval: 900 url: "https://api.bamboohr.com/api/gateway.php" gcal: @@ -14,83 +14,83 @@ wtf: enabled: true eventCount: 10 position: - top: - left: - width: - height: + top: 2 + left: 1 + height: 4 + width: 1 refreshInterval: 300 secretFile: "~/.wtf/gcal/client_secret.json" git: commitCount: 5 enabled: true position: - top: - left: - width: - height: + top: 0 + left: 2 + height: 2 + width: 3 refreshInterval: 8 repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf" github: enabled: true organization: "BetterOfficeApps" position: - top: - left: - width: - height: + top: 2 + left: 2 + height: 2 + width: 3 refreshInterval: 300 repo: "core-api" username: "senorprogrammer" jira: enabled: true position: - top: - left: - width: - height: + top: 1 + left: 1 + height: 1 + width: 1 refreshInterval: 900 newrelic: applicationId: 10549735 enabled: true deployCount: 5 position: - top: - left: - width: - height: + top: 4 + left: 2 + height: 1 + width: 3 refreshInterval: 900 opsgenie: enabled: true position: - top: - left: - width: - height: + top: 2 + left: 0 + height: 2 + width: 1 refreshInterval: 21600 security: - enabled: false + enabled: true position: - top: - left: - width: - height: + top: 5 + left: 0 + height: 1 + width: 1 refreshInterval: 3600 status: enabled: true position: - top: - left: - width: - height: + top: 5 + left: 2 + height: 3 + width: 3 refreshInterval: 1 weather: cityId: 6173331 enabled: true language: "EN" position: - top: - left: - width: - height: + top: 0 + left: 1 + height: 1 + width: 1 tempUnit: "C" refreshInterval: 900 diff --git a/wtf.go b/wtf.go index f5780e02..16d7c4bb 100644 --- a/wtf.go +++ b/wtf.go @@ -1,6 +1,8 @@ package main import ( + //"fmt" + //"os" "time" "github.com/rivo/tview" @@ -37,7 +39,16 @@ func addToApp(grid *tview.Grid, widget wtf.TextViewer) { return } - grid.AddItem(widget.TextView(), 0, 0, 2, 1, 0, 0, false) + grid.AddItem( + widget.TextView(), + widget.Top(), + widget.Left(), + widget.Height(), + widget.Width(), + 0, + 0, + false, // has focus + ) } var result = wtf.CreateConfigDir() @@ -104,17 +115,6 @@ func main() { addToApp(grid, jira) 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() // Loop in a routine to redraw the screen diff --git a/wtf/text_viewer.go b/wtf/text_viewer.go index 374f0173..3c477d8d 100644 --- a/wtf/text_viewer.go +++ b/wtf/text_viewer.go @@ -7,4 +7,8 @@ import ( type TextViewer interface { Enabler TextView() *tview.TextView + Top() int + Left() int + Width() int + Height() int } diff --git a/wtf/text_widget.go b/wtf/text_widget.go index abe91774..8d1f5eb0 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -11,20 +11,39 @@ import ( var Config *config.Config type Position struct { - Top int - Left int - Width int - Height int + top int + left int + width int + height int } +func (pos *Position) Top() int { + return pos.top +} + +func (pos *Position) Left() int { + return pos.left +} + +func (pos *Position) Width() int { + return pos.width +} + +func (pos *Position) Height() int { + return pos.height +} + +/* -------------------- TextWidget -------------------- */ + type TextWidget struct { enabled bool Name string - Position Position RefreshedAt time.Time RefreshInt int View *tview.TextView + + Position } func NewTextWidget(name string, configKey string) TextWidget { @@ -32,6 +51,12 @@ func NewTextWidget(name string, configKey string) TextWidget { enabled: Config.UBool(fmt.Sprintf("wtf.%s.enabled", configKey), false), Name: name, RefreshInt: Config.UInt(fmt.Sprintf("wtf.%s.refreshInterval", configKey)), + Position: Position{ + top: Config.UInt(fmt.Sprintf("wtf.%s.position.top", configKey)), + left: Config.UInt(fmt.Sprintf("wtf.%s.position.left", configKey)), + height: Config.UInt(fmt.Sprintf("wtf.%s.position.height", configKey)), + width: Config.UInt(fmt.Sprintf("wtf.%s.position.width", configKey)), + }, } return widget