Skip to content

Commit

Permalink
Remove complexity from a lot of string display statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Cummer committed Jun 22, 2018
1 parent 24a46a6 commit 1a898b0
Show file tree
Hide file tree
Showing 27 changed files with 85 additions and 86 deletions.
4 changes: 2 additions & 2 deletions bamboohr/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func (widget *Widget) Refresh() {
)

widget.UpdateRefreshedAt()
widget.View.SetTitle(fmt.Sprintf("%s(%d)", widget.Name, len(todayItems)))
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.Name, len(todayItems)))

widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(todayItems)))
widget.View.SetText(widget.contentFrom(todayItems))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
7 changes: 5 additions & 2 deletions circleci/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ func (widget *Widget) Refresh() {

widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name))

var content string
if err != nil {
widget.View.SetWrap(true)
fmt.Fprintf(widget.View, "%v", err)
content = err.Error()
} else {
widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(builds)))
content = widget.contentFrom(builds)
}

widget.View.SetText(content)
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
2 changes: 1 addition & 1 deletion clocks/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func (widget *Widget) display(clocks []Clock) {
)
}

widget.View.SetText(fmt.Sprintf("%s", str))
widget.View.SetText(str)
}
4 changes: 2 additions & 2 deletions cmdrunner/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func (widget *Widget) Refresh() {
widget.execute()

title := wtf.Config.UString("wtf.mods.cmdrunner.title", widget.String())
widget.View.SetTitle(fmt.Sprintf("%s", title))
widget.View.SetTitle(title)

widget.View.SetText(fmt.Sprintf("%s", widget.result))
widget.View.SetText(widget.result)
}

func (widget *Widget) String() string {
Expand Down
7 changes: 2 additions & 5 deletions cryptoexchanges/bittrex/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import (

func (widget *Widget) display() {
if ok == false {
widget.View.SetText(fmt.Sprintf("%s", errorText))
widget.View.SetText(errorText)
return
}

str := ""
str += summaryText(&widget.summaryList, &widget.TextColors)

widget.View.SetText(fmt.Sprintf("%s", str))
widget.View.SetText(summaryText(&widget.summaryList, &widget.TextColors))
}

func summaryText(list *summaryList, colors *TextColors) string {
Expand Down
3 changes: 2 additions & 1 deletion cryptoexchanges/blockfolio/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func (widget *Widget) Refresh() {
if err != nil {
return
}
widget.View.SetText(fmt.Sprintf("%s", contentFrom(positions)))

widget.View.SetText(contentFrom(positions))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
2 changes: 1 addition & 1 deletion gcal/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (widget *Widget) display() {

widget.mutex.Lock()
defer widget.mutex.Unlock()
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.events)))
widget.View.SetText(widget.contentFrom(widget.events))
}

// conflicts returns TRUE if this event conflicts with another, FALSE if it does not
Expand Down
5 changes: 2 additions & 3 deletions git/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
)

func (widget *Widget) display() {

repoData := widget.currentData()
if repoData == nil {
fmt.Fprintf(widget.View, "%s", " Git repo data is unavailable (1)")
widget.View.SetText(" Git repo data is unavailable ")
return
}

Expand All @@ -27,7 +26,7 @@ func (widget *Widget) display() {
str = str + "\n"
str = str + widget.formatCommits(repoData.Commits)

widget.View.SetText(fmt.Sprintf("%s", str))
widget.View.SetText(str)
}

func (widget *Widget) formatChanges(data []string) string {
Expand Down
3 changes: 1 addition & 2 deletions github/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
)

func (widget *Widget) display() {

repo := widget.currentGithubRepo()
if repo == nil {
fmt.Fprintf(widget.View, "%s", " Github repo data is unavailable (1)")
widget.View.SetText(" GitHub repo data is unavailable ")
return
}

Expand Down
2 changes: 1 addition & 1 deletion gitlab/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func (widget *Widget) display() {

project := widget.currentGitlabProject()
if project == nil {
fmt.Fprintf(widget.View, "%s", " Gitlab project data is unavailable (1)")
widget.View.SetText(" Gitlab project data is unavailable ")
return
}

Expand Down
2 changes: 1 addition & 1 deletion gspreadsheets/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (widget *Widget) Refresh() {

widget.UpdateRefreshedAt()

widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(cells)))
widget.View.SetText(widget.contentFrom(cells))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
6 changes: 3 additions & 3 deletions ipaddresses/ipapi/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ func (widget *Widget) ipinfo() {
client := &http.Client{}
req, err := http.NewRequest("GET", "http://ip-api.com/json", nil)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}
req.Header.Set("User-Agent", "curl")
response, err := client.Do(req)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}
defer response.Body.Close()
var info ipinfo
err = json.NewDecoder(response.Body).Decode(&info)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}

Expand Down
6 changes: 3 additions & 3 deletions ipaddresses/ipinfo/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ func (widget *Widget) ipinfo() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://ipinfo.io/", nil)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}
req.Header.Set("User-Agent", "curl")
response, err := client.Do(req)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}
defer response.Body.Close()

var info ipinfo
err = json.NewDecoder(response.Body).Decode(&info)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
widget.result = err.Error()
return
}

Expand Down
16 changes: 7 additions & 9 deletions jenkins/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,20 @@ func (widget *Widget) Refresh() {
)

widget.UpdateRefreshedAt()
widget.View.Clear()
//widget.View.Clear()

var content string
if err != nil {
widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
fmt.Fprintf(widget.View, "%v", err)
content = err.Error()
} else {
widget.View.SetWrap(false)
widget.View.SetTitle(
fmt.Sprintf(
" %s: [green] ",
widget.Name,
),
)
fmt.Fprintf(widget.View, "%s", widget.contentFrom(view))
widget.View.SetTitle(fmt.Sprintf(" %s: [green] ", widget.Name))
content = widget.contentFrom(view)
}

widget.View.SetText(content)
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
9 changes: 6 additions & 3 deletions jira/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ func (widget *Widget) Refresh() {

widget.UpdateRefreshedAt()

var content string
if err != nil {
widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf("%s", widget.Name))
fmt.Fprintf(widget.View, "%v", err)
widget.View.SetTitle(widget.Name)
content = err.Error()
} else {
widget.View.SetWrap(false)
widget.View.SetTitle(
Expand All @@ -42,8 +43,10 @@ func (widget *Widget) Refresh() {
wtf.Config.UString("wtf.mods.jira.project"),
),
)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult)))
content = widget.contentFrom(searchResult)
}

widget.View.SetText(content)
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
4 changes: 2 additions & 2 deletions logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func (widget *Widget) Refresh() {
}

widget.UpdateRefreshedAt()
widget.View.SetTitle(fmt.Sprintf("%s", widget.Name))
widget.View.SetTitle(widget.Name)

logLines := widget.tailFile()
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(logLines)))
widget.View.SetText(widget.contentFrom(logLines))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
7 changes: 5 additions & 2 deletions newrelic/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ func (widget *Widget) Refresh() {
widget.View.SetTitle(fmt.Sprintf("%s- [green]%s[white]", widget.Name, appName))
widget.View.Clear()

var content string
if depErr != nil {
widget.View.SetWrap(true)
widget.View.SetText(fmt.Sprintf("%s", depErr))
content = depErr.Error()
} else {
widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(deploys)))
content = widget.contentFrom(deploys)
}

widget.View.SetText(content)
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
7 changes: 5 additions & 2 deletions opsgenie/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()
widget.View.SetTitle(widget.Name)

var content string
if err != nil {
widget.View.SetWrap(true)
widget.View.SetText(fmt.Sprintf("%s", err))
content = err.Error()
} else {
widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data)))
content = widget.contentFrom(data)
}

widget.View.SetText(content)
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
10 changes: 5 additions & 5 deletions power/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()
widget.Battery.Refresh()

str := ""
str = str + fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
str = str + "\n"
str = str + widget.Battery.String()
content := ""
content = content + fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
content = content + "\n"
content = content + widget.Battery.String()

widget.View.SetText(fmt.Sprintf("%s", str))
widget.View.SetText(content)
}
3 changes: 1 addition & 2 deletions security/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func (widget *Widget) Refresh() {
data.Fetch()

widget.UpdateRefreshedAt()

widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data)))
widget.View.SetText(widget.contentFrom(data))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
4 changes: 1 addition & 3 deletions security/widget_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func (widget *Widget) Refresh() {
data.Fetch()

widget.UpdateRefreshedAt()
widget.View.Clear()

fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
widget.View.SetText(widget.contentFrom(data))
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
10 changes: 1 addition & 9 deletions status/widget.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package status

import (
"fmt"

"github.com/senorprogrammer/wtf/wtf"
)

Expand All @@ -25,13 +23,7 @@ func NewWidget() *Widget {

func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()

widget.View.SetText(
fmt.Sprintf(
"\n%s",
widget.animation(),
),
)
widget.View.SetText(widget.animation())
}

/* -------------------- Unexported Functions -------------------- */
Expand Down
4 changes: 2 additions & 2 deletions textfile/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (widget *Widget) Refresh() {
}

if err != nil {
widget.View.SetText(fmt.Sprintf("%s", err))
widget.View.SetText(err.Error())
} else {
widget.View.SetText(fmt.Sprintf("%s", string(fileData)))
widget.View.SetText(string(fileData))
}
}

Expand Down
2 changes: 1 addition & 1 deletion todo/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (widget *Widget) display() {
widget.SetList(&newList)

widget.View.Clear()
widget.View.SetText(fmt.Sprintf("%s", str))
widget.View.SetText(str)
}

func (widget *Widget) formattedItemLine(item *Item, selectedItem *Item, maxLen int) string {
Expand Down
Loading

0 comments on commit 1a898b0

Please sign in to comment.