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

Remove complexity from a lot of string display statements

This commit is contained in:
Chris Cummer 2018-06-21 19:32:32 -07:00
parent 24a46a652b
commit 1a898b05e3
27 changed files with 85 additions and 86 deletions

View File

@ -31,7 +31,7 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() 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 -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -30,13 +30,16 @@ func (widget *Widget) Refresh() {
widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name)) widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name))
var content string
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
fmt.Fprintf(widget.View, "%v", err) content = err.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(builds))) content = widget.contentFrom(builds)
} }
widget.View.SetText(content)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -23,5 +23,5 @@ func (widget *Widget) display(clocks []Clock) {
) )
} }
widget.View.SetText(fmt.Sprintf("%s", str)) widget.View.SetText(str)
} }

View File

@ -34,9 +34,9 @@ func (widget *Widget) Refresh() {
widget.execute() widget.execute()
title := wtf.Config.UString("wtf.mods.cmdrunner.title", widget.String()) 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 { func (widget *Widget) String() string {

View File

@ -8,14 +8,11 @@ import (
func (widget *Widget) display() { func (widget *Widget) display() {
if ok == false { if ok == false {
widget.View.SetText(fmt.Sprintf("%s", errorText)) widget.View.SetText(errorText)
return return
} }
str := "" widget.View.SetText(summaryText(&widget.summaryList, &widget.TextColors))
str += summaryText(&widget.summaryList, &widget.TextColors)
widget.View.SetText(fmt.Sprintf("%s", str))
} }
func summaryText(list *summaryList, colors *TextColors) string { func summaryText(list *summaryList, colors *TextColors) string {

View File

@ -37,7 +37,8 @@ func (widget *Widget) Refresh() {
if err != nil { if err != nil {
return return
} }
widget.View.SetText(fmt.Sprintf("%s", contentFrom(positions)))
widget.View.SetText(contentFrom(positions))
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -55,7 +55,7 @@ func (widget *Widget) display() {
widget.mutex.Lock() widget.mutex.Lock()
defer widget.mutex.Unlock() 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 // conflicts returns TRUE if this event conflicts with another, FALSE if it does not

View File

@ -9,10 +9,9 @@ import (
) )
func (widget *Widget) display() { func (widget *Widget) display() {
repoData := widget.currentData() repoData := widget.currentData()
if repoData == nil { if repoData == nil {
fmt.Fprintf(widget.View, "%s", " Git repo data is unavailable (1)") widget.View.SetText(" Git repo data is unavailable ")
return return
} }
@ -27,7 +26,7 @@ func (widget *Widget) display() {
str = str + "\n" str = str + "\n"
str = str + widget.formatCommits(repoData.Commits) str = str + widget.formatCommits(repoData.Commits)
widget.View.SetText(fmt.Sprintf("%s", str)) widget.View.SetText(str)
} }
func (widget *Widget) formatChanges(data []string) string { func (widget *Widget) formatChanges(data []string) string {

View File

@ -7,10 +7,9 @@ import (
) )
func (widget *Widget) display() { func (widget *Widget) display() {
repo := widget.currentGithubRepo() repo := widget.currentGithubRepo()
if repo == nil { if repo == nil {
fmt.Fprintf(widget.View, "%s", " Github repo data is unavailable (1)") widget.View.SetText(" GitHub repo data is unavailable ")
return return
} }

View File

@ -10,7 +10,7 @@ func (widget *Widget) display() {
project := widget.currentGitlabProject() project := widget.currentGitlabProject()
if project == nil { if project == nil {
fmt.Fprintf(widget.View, "%s", " Gitlab project data is unavailable (1)") widget.View.SetText(" Gitlab project data is unavailable ")
return return
} }

View File

@ -26,7 +26,7 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(cells))) widget.View.SetText(widget.contentFrom(cells))
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -61,20 +61,20 @@ func (widget *Widget) ipinfo() {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("GET", "http://ip-api.com/json", nil) req, err := http.NewRequest("GET", "http://ip-api.com/json", nil)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }
req.Header.Set("User-Agent", "curl") req.Header.Set("User-Agent", "curl")
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }
defer response.Body.Close() defer response.Body.Close()
var info ipinfo var info ipinfo
err = json.NewDecoder(response.Body).Decode(&info) err = json.NewDecoder(response.Body).Decode(&info)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }

View File

@ -55,13 +55,13 @@ func (widget *Widget) ipinfo() {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("GET", "https://ipinfo.io/", nil) req, err := http.NewRequest("GET", "https://ipinfo.io/", nil)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }
req.Header.Set("User-Agent", "curl") req.Header.Set("User-Agent", "curl")
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }
defer response.Body.Close() defer response.Body.Close()
@ -69,7 +69,7 @@ func (widget *Widget) ipinfo() {
var info ipinfo var info ipinfo
err = json.NewDecoder(response.Body).Decode(&info) err = json.NewDecoder(response.Body).Decode(&info)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }

View File

@ -32,22 +32,20 @@ func (widget *Widget) Refresh() {
) )
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.Clear() //widget.View.Clear()
var content string
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name)) widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
fmt.Fprintf(widget.View, "%v", err) content = err.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetTitle( widget.View.SetTitle(fmt.Sprintf(" %s: [green] ", widget.Name))
fmt.Sprintf( content = widget.contentFrom(view)
" %s: [green] ",
widget.Name,
),
)
fmt.Fprintf(widget.View, "%s", widget.contentFrom(view))
} }
widget.View.SetText(content)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -29,10 +29,11 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
var content string
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf("%s", widget.Name)) widget.View.SetTitle(widget.Name)
fmt.Fprintf(widget.View, "%v", err) content = err.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetTitle( widget.View.SetTitle(
@ -42,8 +43,10 @@ func (widget *Widget) Refresh() {
wtf.Config.UString("wtf.mods.jira.project"), 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 -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -52,10 +52,10 @@ func (widget *Widget) Refresh() {
} }
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.SetTitle(fmt.Sprintf("%s", widget.Name)) widget.View.SetTitle(widget.Name)
logLines := widget.tailFile() logLines := widget.tailFile()
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(logLines))) widget.View.SetText(widget.contentFrom(logLines))
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -34,13 +34,16 @@ func (widget *Widget) Refresh() {
widget.View.SetTitle(fmt.Sprintf("%s- [green]%s[white]", widget.Name, appName)) widget.View.SetTitle(fmt.Sprintf("%s- [green]%s[white]", widget.Name, appName))
widget.View.Clear() widget.View.Clear()
var content string
if depErr != nil { if depErr != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.View.SetText(fmt.Sprintf("%s", depErr)) content = depErr.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(deploys))) content = widget.contentFrom(deploys)
} }
widget.View.SetText(content)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -27,13 +27,16 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.SetTitle(widget.Name) widget.View.SetTitle(widget.Name)
var content string
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.View.SetText(fmt.Sprintf("%s", err)) content = err.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data))) content = widget.contentFrom(data)
} }
widget.View.SetText(content)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -27,10 +27,10 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.Battery.Refresh() widget.Battery.Refresh()
str := "" content := ""
str = str + fmt.Sprintf(" %10s: %s\n", "Source", powerSource()) content = content + fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
str = str + "\n" content = content + "\n"
str = str + widget.Battery.String() content = content + widget.Battery.String()
widget.View.SetText(fmt.Sprintf("%s", str)) widget.View.SetText(content)
} }

View File

@ -28,8 +28,7 @@ func (widget *Widget) Refresh() {
data.Fetch() data.Fetch()
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.SetText(widget.contentFrom(data))
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(data)))
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -32,9 +32,7 @@ func (widget *Widget) Refresh() {
data.Fetch() data.Fetch()
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.Clear() widget.View.SetText(widget.contentFrom(data))
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -1,8 +1,6 @@
package status package status
import ( import (
"fmt"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
) )
@ -25,13 +23,7 @@ func NewWidget() *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.View.SetText(widget.animation())
widget.View.SetText(
fmt.Sprintf(
"\n%s",
widget.animation(),
),
)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -55,9 +55,9 @@ func (widget *Widget) Refresh() {
} }
if err != nil { if err != nil {
widget.View.SetText(fmt.Sprintf("%s", err)) widget.View.SetText(err.Error())
} else { } else {
widget.View.SetText(fmt.Sprintf("%s", string(fileData))) widget.View.SetText(string(fileData))
} }
} }

View File

@ -29,7 +29,7 @@ func (widget *Widget) display() {
widget.SetList(&newList) widget.SetList(&newList)
widget.View.Clear() 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 { func (widget *Widget) formattedItemLine(item *Item, selectedItem *Item, maxLen int) string {

View File

@ -29,10 +29,11 @@ func (widget *Widget) Refresh() {
searchResult, err := GetCards(client, getLists()) searchResult, err := GetCards(client, getLists())
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
var content string
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf("%s", widget.Name)) widget.View.SetTitle(widget.Name)
fmt.Fprintf(widget.View, "%v", err) content = err.Error()
} else { } else {
widget.View.SetWrap(false) widget.View.SetWrap(false)
widget.View.SetTitle( widget.View.SetTitle(
@ -42,8 +43,10 @@ func (widget *Widget) Refresh() {
wtf.Config.UString("wtf.mods.trello.board"), wtf.Config.UString("wtf.mods.trello.board"),
), ),
) )
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult))) content = widget.contentFrom(searchResult)
} }
widget.View.SetText(content)
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -1,7 +1,6 @@
package prettyweather package prettyweather
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -29,7 +28,7 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt() widget.UpdateRefreshedAt()
widget.prettyWeather() widget.prettyWeather()
widget.View.SetText(fmt.Sprintf("%s", widget.result)) widget.View.SetText(widget.result)
} }
//this method reads the config and calls wttr.in for pretty weather //this method reads the config and calls wttr.in for pretty weather
@ -40,21 +39,24 @@ func (widget *Widget) prettyWeather() {
widget.view = wtf.Config.UString("wtf.mods.prettyweather.view", "0") widget.view = wtf.Config.UString("wtf.mods.prettyweather.view", "0")
req, err := http.NewRequest("GET", "https://wttr.in/"+widget.city+"?"+widget.view+"?"+widget.unit, nil) req, err := http.NewRequest("GET", "https://wttr.in/"+widget.city+"?"+widget.view+"?"+widget.unit, nil)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
} }
req.Header.Set("User-Agent", "curl") req.Header.Set("User-Agent", "curl")
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
widget.result = fmt.Sprintf("%s", err.Error()) widget.result = err.Error()
return return
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
widget.result = fmt.Sprintf("%s", err.Error())
return
}
widget.result = fmt.Sprintf("%s", strings.TrimSpace(string(contents)))
} }
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
widget.result = err.Error()
return
}
widget.result = strings.TrimSpace(string(contents))
}

View File

@ -9,32 +9,31 @@ import (
) )
func (widget *Widget) display() { func (widget *Widget) display() {
widget.View.Clear()
if widget.apiKeyValid() == false { if widget.apiKeyValid() == false {
fmt.Fprintf(widget.View, "%s", " Environment variable WTF_OWM_API_KEY is not set") widget.View.SetText(" Environment variable WTF_OWM_API_KEY is not set")
return return
} }
cityData := widget.currentData() cityData := widget.currentData()
if cityData == nil { if cityData == nil {
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (1)") widget.View.SetText(" Weather data is unavailable: no city data")
return return
} }
if len(cityData.Weather) == 0 { if len(cityData.Weather) == 0 {
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (2)") widget.View.SetText(" Weather data is unavailable: no weather data")
return return
} }
widget.View.SetTitle(widget.title(cityData)) widget.View.SetTitle(widget.title(cityData))
str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n" content := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n"
str = str + widget.description(cityData) + "\n\n" content = content + widget.description(cityData) + "\n\n"
str = str + widget.temperatures(cityData) + "\n" content = content + widget.temperatures(cityData) + "\n"
str = str + widget.sunInfo(cityData) content = content + widget.sunInfo(cityData)
fmt.Fprintf(widget.View, "%s", str) widget.View.SetText(content)
} }
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string { func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {