From 6443df092f5eeb3d9cb253a4b7a3bdb0ff943bb3 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Sun, 3 Jun 2018 10:53:26 +0430 Subject: [PATCH] use widget.View.SetText to print --- bamboohr/widget.go | 3 +-- clocks/display.go | 2 +- clocks/widget.go | 1 - cmdrunner/widget.go | 3 +-- gcal/widget.go | 3 +-- git/display.go | 3 +-- github/display.go | 3 +-- jira/widget.go | 3 +-- newrelic/widget.go | 6 +++--- opsgenie/widget.go | 5 ++--- power/widget.go | 3 +-- prettyweather/widget.go | 8 ++++---- security/widget.go | 3 +-- status/widget.go | 10 +++++----- system/widget.go | 24 ++++++++++++------------ textfile/widget.go | 5 ++--- todo/display.go | 2 +- 17 files changed, 38 insertions(+), 49 deletions(-) diff --git a/bamboohr/widget.go b/bamboohr/widget.go index a8997013..a2b5f443 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -38,9 +38,8 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(todayItems))) - widget.View.Clear() - fmt.Fprintf(widget.View, "%s", widget.contentFrom(todayItems)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(todayItems))) } /* -------------------- Unexported Functions -------------------- */ diff --git a/clocks/display.go b/clocks/display.go index 1cf632e9..6cc7d60f 100644 --- a/clocks/display.go +++ b/clocks/display.go @@ -23,5 +23,5 @@ func (widget *Widget) display(clocks []Clock) { ) } - fmt.Fprintf(widget.View, "%s", str) + widget.View.SetText(fmt.Sprintf("%s", str)) } diff --git a/clocks/widget.go b/clocks/widget.go index e5214fb6..3dff6cae 100644 --- a/clocks/widget.go +++ b/clocks/widget.go @@ -34,7 +34,6 @@ func (widget *Widget) Refresh() { } widget.UpdateRefreshedAt() - widget.View.Clear() widget.display(widget.clockColl.Sorted()) } diff --git a/cmdrunner/widget.go b/cmdrunner/widget.go index a489cd2c..bb25dac6 100644 --- a/cmdrunner/widget.go +++ b/cmdrunner/widget.go @@ -40,10 +40,9 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.execute() - widget.View.Clear() widget.View.SetTitle(fmt.Sprintf(" %s ", widget)) - fmt.Fprintf(widget.View, "%s", widget.result) + widget.View.SetText(fmt.Sprintf("%s", widget.result)) } func (widget *Widget) String() string { diff --git a/gcal/widget.go b/gcal/widget.go index 112be1ca..6e2df90c 100644 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -36,9 +36,8 @@ func (widget *Widget) Refresh() { events, _ := Fetch() widget.UpdateRefreshedAt() - widget.View.Clear() - fmt.Fprintf(widget.View, "%s", widget.contentFrom(events)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(events))) } /* -------------------- Unexported Functions -------------------- */ diff --git a/git/display.go b/git/display.go index e6fffe34..e809224f 100644 --- a/git/display.go +++ b/git/display.go @@ -9,7 +9,6 @@ import ( ) func (widget *Widget) display() { - widget.View.Clear() repoData := widget.currentData() if repoData == nil { @@ -28,7 +27,7 @@ func (widget *Widget) display() { str = str + "\n" str = str + widget.formatCommits(repoData.Commits) - fmt.Fprintf(widget.View, "%s", str) + widget.View.SetText(fmt.Sprintf("%s", str)) } func (widget *Widget) formatChanges(data []string) string { diff --git a/github/display.go b/github/display.go index a3732369..1d35ef1b 100644 --- a/github/display.go +++ b/github/display.go @@ -7,7 +7,6 @@ import ( ) func (widget *Widget) display() { - widget.View.Clear() repo := widget.currentGithubRepo() if repo == nil { @@ -27,7 +26,7 @@ func (widget *Widget) display() { str = str + " [red]My Pull Requests[white]\n" str = str + widget.displayMyPullRequests(repo, Config.UString("wtf.mods.github.username")) - fmt.Fprintf(widget.View, str) + widget.View.SetText(str) } func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { diff --git a/jira/widget.go b/jira/widget.go index ed3c11c3..ebe85237 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -32,7 +32,6 @@ func (widget *Widget) Refresh() { searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), Config.UString("wtf.mods.jira.project", ""), Config.UString("wtf.mods.jira.jql", "")) widget.UpdateRefreshedAt() - widget.View.Clear() if err != nil { widget.View.SetWrap(true) @@ -47,7 +46,7 @@ func (widget *Widget) Refresh() { Config.UString("wtf.mods.jira.project"), ), ) - fmt.Fprintf(widget.View, "%s", widget.contentFrom(searchResult)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult))) } } diff --git a/newrelic/widget.go b/newrelic/widget.go index c4076af9..61a72a95 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -44,10 +44,10 @@ func (widget *Widget) Refresh() { if depErr != nil { widget.View.SetWrap(true) - fmt.Fprintf(widget.View, "%s", depErr) + widget.View.SetText(fmt.Sprintf("%s", depErr)) } else { widget.View.SetWrap(false) - fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(deploys))) } } @@ -70,7 +70,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { var revLen = 8 if revLen > len(deploy.Revision) { - revLen = len(deploy.Revision) + revLen = len(deploy.Revision) } str = str + fmt.Sprintf( diff --git a/opsgenie/widget.go b/opsgenie/widget.go index 3a75ce37..1089c918 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -34,14 +34,13 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.View.SetTitle(" ⏰ On Call ") - widget.View.Clear() if err != nil { widget.View.SetWrap(true) - fmt.Fprintf(widget.View, "%s", err) + widget.View.SetText(fmt.Sprintf("%s", err)) } else { widget.View.SetWrap(false) - fmt.Fprintf(widget.View, "%s", widget.contentFrom(data)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data))) } } diff --git a/power/widget.go b/power/widget.go index f971bec8..bd7a3652 100644 --- a/power/widget.go +++ b/power/widget.go @@ -34,12 +34,11 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.Battery.Refresh() - widget.View.Clear() str := "" str = str + fmt.Sprintf(" %10s: %s\n", "Source", powerSource()) str = str + "\n" str = str + widget.Battery.String() - fmt.Fprintf(widget.View, "%s", str) + widget.View.SetText(fmt.Sprintf("%s", str)) } diff --git a/prettyweather/widget.go b/prettyweather/widget.go index 0dcea050..d4e237ea 100644 --- a/prettyweather/widget.go +++ b/prettyweather/widget.go @@ -2,11 +2,12 @@ package prettyweather import ( "fmt" - "github.com/olebedev/config" - "github.com/senorprogrammer/wtf/wtf" "io/ioutil" "net/http" "strings" + + "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/wtf" ) // Config is a pointer to the global config object @@ -34,10 +35,9 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.prettyWeather() - widget.View.Clear() widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) - fmt.Fprintf(widget.View, "%s", widget.result) + widget.View.SetText(fmt.Sprintf("%s", widget.result)) } //this method reads the config and calls wttr.in for pretty weather diff --git a/security/widget.go b/security/widget.go index 61bab3b2..2ec6ba3f 100644 --- a/security/widget.go +++ b/security/widget.go @@ -34,9 +34,8 @@ func (widget *Widget) Refresh() { data.Fetch() widget.UpdateRefreshedAt() - widget.View.Clear() - fmt.Fprintf(widget.View, "%s", widget.contentFrom(data)) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data))) } /* -------------------- Unexported Functions -------------------- */ diff --git a/status/widget.go b/status/widget.go index a4f2b4d0..83d2861e 100644 --- a/status/widget.go +++ b/status/widget.go @@ -33,12 +33,12 @@ func (widget *Widget) Refresh() { } widget.UpdateRefreshedAt() - widget.View.Clear() - fmt.Fprintf( - widget.View, - "\n%s", - widget.animation(), + widget.View.SetText( + fmt.Sprintf( + "\n%s", + widget.animation(), + ), ) } diff --git a/system/widget.go b/system/widget.go index 5cfc8e60..6da695f8 100644 --- a/system/widget.go +++ b/system/widget.go @@ -38,19 +38,19 @@ func (widget *Widget) Refresh() { } widget.UpdateRefreshedAt() - widget.View.Clear() - fmt.Fprintf( - widget.View, - "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", - "Built", - widget.prettyDate(), - "Vers", - widget.Version, - "OS", - widget.systemInfo.ProductVersion, - "Build", - widget.systemInfo.BuildVersion, + widget.View.SetText( + fmt.Sprintf( + "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", + "Built", + widget.prettyDate(), + "Vers", + widget.Version, + "OS", + widget.systemInfo.ProductVersion, + "Build", + widget.systemInfo.BuildVersion, + ), ) } diff --git a/textfile/widget.go b/textfile/widget.go index e452c0d7..12f2a7fa 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -54,7 +54,6 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.View.SetTitle(fmt.Sprintf(" 📄 %s ", widget.filePath)) - widget.View.Clear() filePath, _ := wtf.ExpandHomeDir(widget.filePath) @@ -64,9 +63,9 @@ func (widget *Widget) Refresh() { } if err != nil { - fmt.Fprintf(widget.View, "%s", err) + widget.View.SetText(fmt.Sprintf("%s", err)) } else { - fmt.Fprintf(widget.View, "%s", string(fileData)) + widget.View.SetText(fmt.Sprintf("%s", string(fileData))) } } diff --git a/todo/display.go b/todo/display.go index 98f3eb72..d25d20cb 100644 --- a/todo/display.go +++ b/todo/display.go @@ -29,7 +29,7 @@ func (widget *Widget) display() { widget.SetList(&newList) widget.View.Clear() - fmt.Fprintf(widget.View, "%s", str) + widget.View.SetText(fmt.Sprintf("%s", str)) } func (widget *Widget) formattedItemLine(item *Item, selectedItem *Item, maxLen int) string {