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:
parent
24a46a652b
commit
1a898b05e3
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -23,5 +23,5 @@ func (widget *Widget) display(clocks []Clock) {
|
||||
)
|
||||
}
|
||||
|
||||
widget.View.SetText(fmt.Sprintf("%s", str))
|
||||
widget.View.SetText(str)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -55,13 +55,13 @@ 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()
|
||||
@ -69,7 +69,7 @@ func (widget *Widget) ipinfo() {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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(
|
||||
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -1,8 +1,6 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
@ -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 -------------------- */
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -29,10 +29,11 @@ func (widget *Widget) Refresh() {
|
||||
searchResult, err := GetCards(client, getLists())
|
||||
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(
|
||||
@ -42,8 +43,10 @@ func (widget *Widget) Refresh() {
|
||||
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 -------------------- */
|
||||
|
@ -1,7 +1,6 @@
|
||||
package prettyweather
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -29,7 +28,7 @@ func (widget *Widget) Refresh() {
|
||||
widget.UpdateRefreshedAt()
|
||||
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
|
||||
@ -40,21 +39,24 @@ func (widget *Widget) prettyWeather() {
|
||||
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)
|
||||
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()
|
||||
|
||||
contents, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
widget.result = fmt.Sprintf("%s", err.Error())
|
||||
widget.result = err.Error()
|
||||
return
|
||||
}
|
||||
widget.result = fmt.Sprintf("%s", strings.TrimSpace(string(contents)))
|
||||
|
||||
widget.result = strings.TrimSpace(string(contents))
|
||||
}
|
||||
|
@ -9,32 +9,31 @@ import (
|
||||
)
|
||||
|
||||
func (widget *Widget) display() {
|
||||
widget.View.Clear()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
cityData := widget.currentData()
|
||||
if cityData == nil {
|
||||
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (1)")
|
||||
widget.View.SetText(" Weather data is unavailable: no city data")
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.title(cityData))
|
||||
|
||||
str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n"
|
||||
str = str + widget.description(cityData) + "\n\n"
|
||||
str = str + widget.temperatures(cityData) + "\n"
|
||||
str = str + widget.sunInfo(cityData)
|
||||
content := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n"
|
||||
content = content + widget.description(cityData) + "\n\n"
|
||||
content = content + widget.temperatures(cityData) + "\n"
|
||||
content = content + widget.sunInfo(cityData)
|
||||
|
||||
fmt.Fprintf(widget.View, "%s", str)
|
||||
widget.View.SetText(content)
|
||||
}
|
||||
|
||||
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {
|
||||
@ -73,5 +72,5 @@ func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string {
|
||||
}
|
||||
|
||||
func (widget *Widget) title(cityData *owm.CurrentWeatherData) string {
|
||||
return fmt.Sprintf(" %s %s ", widget.icon(cityData), cityData.Name)
|
||||
return fmt.Sprintf(" %s %s ", widget.icon(cityData), cityData.Name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user