From f0771cd0139be037b907509b37587c129961a62f Mon Sep 17 00:00:00 2001 From: Kirill Motkov Date: Tue, 21 May 2019 17:17:47 +0300 Subject: [PATCH] Some code improvements * Some assignments simplified by using assignment operators * Rewrite switch statement with only one case as if. * Rewrite if-else chain as a switch statement. * go fmt `modules/todoist/project.go` file. --- cfg/common_settings.go | 4 +-- checklist/checklist.go | 4 +-- modules/bamboohr/widget.go | 2 +- modules/circleci/widget.go | 2 +- modules/clocks/display.go | 2 +- modules/cryptoexchanges/blockfolio/widget.go | 6 ++-- modules/datadog/widget.go | 7 ++-- modules/gcal/display.go | 4 +-- modules/gerrit/display.go | 20 ++++++------ modules/gerrit/widget.go | 4 +-- modules/git/display.go | 24 +++++++------- modules/github/display.go | 20 ++++++------ modules/gitlab/display.go | 20 ++++++------ modules/gitlab/widget.go | 4 +-- modules/gitter/widget.go | 4 +-- modules/gspreadsheets/widget.go | 2 +- modules/hackernews/widget.go | 4 +-- modules/jenkins/client.go | 4 +-- modules/jenkins/widget.go | 4 +-- modules/jira/widget.go | 2 +- modules/logger/widget.go | 2 +- modules/mercurial/display.go | 24 +++++++------- modules/nbascore/widget.go | 18 ++++++----- modules/newrelic/widget.go | 2 +- modules/opsgenie/widget.go | 4 +-- modules/pagerduty/widget.go | 20 ++++++------ modules/power/battery_linux.go | 9 +++--- modules/power/widget.go | 7 ++-- modules/rollbar/widget.go | 2 +- modules/security/widget.go | 34 ++++++++++---------- modules/security/wifi.go | 3 +- modules/status/widget.go | 2 +- modules/textfile/widget.go | 4 +-- modules/todo/display.go | 4 +-- modules/todoist/project.go | 14 ++++---- modules/travisci/widget.go | 2 +- modules/trello/client.go | 2 +- modules/trello/widget.go | 4 +-- modules/twitter/widget.go | 2 +- modules/weatherservices/weather/display.go | 10 +++--- modules/weatherservices/weather/widget.go | 4 +-- modules/zendesk/widget.go | 2 +- wtf/billboard_modal.go | 3 +- wtf/focus_tracker.go | 4 +-- wtf/keyboard_widget.go | 6 ++-- wtf/multisource_widget.go | 4 +-- 46 files changed, 164 insertions(+), 171 deletions(-) diff --git a/cfg/common_settings.go b/cfg/common_settings.go index 7f53aa673..d80ab0a03 100644 --- a/cfg/common_settings.go +++ b/cfg/common_settings.go @@ -148,8 +148,8 @@ func (common *Common) SigilStr(len, pos int, width int) string { if len > 1 { sigils = strings.Repeat(common.Sigils.Paging.Normal, pos) - sigils = sigils + common.Sigils.Paging.Selected - sigils = sigils + strings.Repeat(common.Sigils.Paging.Normal, len-1-pos) + sigils += common.Sigils.Paging.Selected + sigils += strings.Repeat(common.Sigils.Paging.Normal, len-1-pos) sigils = "[lightblue]" + fmt.Sprintf(common.RightAlignFormat(width), sigils) + "[white]" } diff --git a/checklist/checklist.go b/checklist/checklist.go index d65e1d9fc..4ff75a780 100644 --- a/checklist/checklist.go +++ b/checklist/checklist.go @@ -140,7 +140,7 @@ func (list *Checklist) Update(text string) { // Prev selects the previous item UP in the checklist func (list *Checklist) Prev() { - list.selected = list.selected - 1 + list.selected-- if list.selected < 0 { list.selected = len(list.Items) - 1 } @@ -148,7 +148,7 @@ func (list *Checklist) Prev() { // Next selects the next item DOWN in the checklist func (list *Checklist) Next() { - list.selected = list.selected + 1 + list.selected++ if list.selected >= len(list.Items) { list.selected = 0 } diff --git a/modules/bamboohr/widget.go b/modules/bamboohr/widget.go index 8885fe6cd..2bfd2143e 100644 --- a/modules/bamboohr/widget.go +++ b/modules/bamboohr/widget.go @@ -54,7 +54,7 @@ func (widget *Widget) contentFrom(items []Item) string { str := "" for _, item := range items { - str = str + widget.format(item) + str += widget.format(item) } return str diff --git a/modules/circleci/widget.go b/modules/circleci/widget.go index 64f09b1b3..97d604738 100644 --- a/modules/circleci/widget.go +++ b/modules/circleci/widget.go @@ -56,7 +56,7 @@ func (widget *Widget) contentFrom(builds []*Build) string { return str } - str = str + fmt.Sprintf( + str += fmt.Sprintf( "[%s] %s-%d (%s) [white]%s\n", buildColor(build), build.Reponame, diff --git a/modules/clocks/display.go b/modules/clocks/display.go index eae5d0759..1b13a0364 100644 --- a/modules/clocks/display.go +++ b/modules/clocks/display.go @@ -19,7 +19,7 @@ func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat stri rowColor = widget.settings.colors.rows.even } - str = str + fmt.Sprintf( + str += fmt.Sprintf( " [%s]%-12s %-10s %7s[white]\n", rowColor, clock.Label, diff --git a/modules/cryptoexchanges/blockfolio/widget.go b/modules/cryptoexchanges/blockfolio/widget.go index 5aa414726..f4154787a 100644 --- a/modules/cryptoexchanges/blockfolio/widget.go +++ b/modules/cryptoexchanges/blockfolio/widget.go @@ -60,7 +60,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string { totalFiat += positions.PositionList[i].HoldingValueFiat if widget.settings.displayHoldings { - res = res + fmt.Sprintf( + res += fmt.Sprintf( "[%s]%-6s - %5.2f ([%s]%.3fk [%s]%.2f%s)\n", widget.settings.colors.name, positions.PositionList[i].Coin, @@ -72,7 +72,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string { "%", ) } else { - res = res + fmt.Sprintf( + res += fmt.Sprintf( "[%s]%-6s - %5.2f ([%s]%.2f%s)\n", widget.settings.colors.name, positions.PositionList[i].Coin, @@ -85,7 +85,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string { } if widget.settings.displayHoldings { - res = res + fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000) + res += fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000) } return res diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index 3ca489e08..d1b6142a1 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -48,8 +48,7 @@ func (widget *Widget) Refresh() { for _, monitor := range monitors { state := *monitor.OverallState - switch state { - case "Alert": + if state == "Alert" { triggeredMonitors = append(triggeredMonitors, monitor) } } @@ -74,7 +73,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string { var str string if len(triggeredMonitors) > 0 { - str = str + fmt.Sprintf( + str += fmt.Sprintf( " %s\n", "[red]Triggered Monitors[white]", ) @@ -87,7 +86,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string { ) + "\n" } } else { - str = str + fmt.Sprintf( + str += fmt.Sprintf( " %s\n", "[green]No Triggered Monitors[white]", ) diff --git a/modules/gcal/display.go b/modules/gcal/display.go index 65ee72211..3b245d596 100644 --- a/modules/gcal/display.go +++ b/modules/gcal/display.go @@ -63,14 +63,14 @@ func (widget *Widget) contentFrom(calEvents []*CalEvent) string { title, ) - str = str + fmt.Sprintf("%s %s%s\n", + str += fmt.Sprintf("%s %s%s\n", lineOne, widget.location(calEvent), widget.timeUntil(calEvent), ) if (widget.location(calEvent) != "") || (widget.timeUntil(calEvent) != "") { - str = str + "\n" + str += "\n" } prevEvent = calEvent diff --git a/modules/gerrit/display.go b/modules/gerrit/display.go index 8fc9e1885..86cf68895 100644 --- a/modules/gerrit/display.go +++ b/modules/gerrit/display.go @@ -16,14 +16,14 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n" - str = str + " [red]Stats[white]\n" - str = str + widget.displayStats(project) - str = str + "\n" - str = str + " [red]Open Incoming Reviews[white]\n" - str = str + widget.displayMyIncomingReviews(project, widget.settings.username) - str = str + "\n" - str = str + " [red]My Outgoing Reviews[white]\n" - str = str + widget.displayMyOutgoingReviews(project, widget.settings.username) + str += " [red]Stats[white]\n" + str += widget.displayStats(project) + str += "\n" + str += " [red]Open Incoming Reviews[white]\n" + str += widget.displayMyIncomingReviews(project, widget.settings.username) + str += "\n" + str += " [red]My Outgoing Reviews[white]\n" + str += widget.displayMyOutgoingReviews(project, widget.settings.username) widget.Redraw(title, str, false) } @@ -35,7 +35,7 @@ func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username str := "" for idx, r := range project.IncomingReviews { - str = str + fmt.Sprintf(" [%s] [green]%d[white] [%s] %s\n", widget.rowColor(idx), r.Number, widget.rowColor(idx), r.Subject) + str += fmt.Sprintf(" [%s] [green]%d[white] [%s] %s\n", widget.rowColor(idx), r.Number, widget.rowColor(idx), r.Subject) } return str @@ -48,7 +48,7 @@ func (widget *Widget) displayMyOutgoingReviews(project *GerritProject, username str := "" for idx, r := range project.OutgoingReviews { - str = str + fmt.Sprintf(" [%s] [green]%d[white] [%s] %s\n", widget.rowColor(idx+len(project.IncomingReviews)), r.Number, widget.rowColor(idx+len(project.IncomingReviews)), r.Subject) + str += fmt.Sprintf(" [%s] [green]%d[white] [%s] %s\n", widget.rowColor(idx+len(project.IncomingReviews)), r.Number, widget.rowColor(idx+len(project.IncomingReviews)), r.Subject) } return str diff --git a/modules/gerrit/widget.go b/modules/gerrit/widget.go index 2e7d914f7..89f2c2e9d 100644 --- a/modules/gerrit/widget.go +++ b/modules/gerrit/widget.go @@ -97,7 +97,7 @@ func (widget *Widget) HelpText() string { /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) nextProject() { - widget.Idx = widget.Idx + 1 + widget.Idx++ widget.unselect() if widget.Idx == len(widget.GerritProjects) { widget.Idx = 0 @@ -107,7 +107,7 @@ func (widget *Widget) nextProject() { } func (widget *Widget) prevProject() { - widget.Idx = widget.Idx - 1 + widget.Idx-- if widget.Idx < 0 { widget.Idx = len(widget.GerritProjects) - 1 } diff --git a/modules/git/display.go b/modules/git/display.go index 85712c2c3..c3683cb2d 100644 --- a/modules/git/display.go +++ b/modules/git/display.go @@ -17,25 +17,24 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GitRepos), widget.Idx, width) + "\n" - str = str + " [red]Branch[white]\n" - str = str + fmt.Sprintf(" %s", repoData.Branch) - str = str + "\n" - str = str + widget.formatChanges(repoData.ChangedFiles) - str = str + "\n" - str = str + widget.formatCommits(repoData.Commits) + str += " [red]Branch[white]\n" + str += fmt.Sprintf(" %s", repoData.Branch) + str += "\n" + str += widget.formatChanges(repoData.ChangedFiles) + str += "\n" + str += widget.formatCommits(repoData.Commits) widget.Redraw(title, str, false) } func (widget *Widget) formatChanges(data []string) string { - str := "" - str = str + " [red]Changed Files[white]\n" + str := " [red]Changed Files[white]\n" if len(data) == 1 { - str = str + " [grey]none[white]\n" + str += " [grey]none[white]\n" } else { for _, line := range data { - str = str + widget.formatChange(line) + str += widget.formatChange(line) } } @@ -66,11 +65,10 @@ func (widget *Widget) formatChange(line string) string { } func (widget *Widget) formatCommits(data []string) string { - str := "" - str = str + " [red]Recent Commits[white]\n" + str := " [red]Recent Commits[white]\n" for _, line := range data { - str = str + widget.formatCommit(line) + str += widget.formatCommit(line) } return str diff --git a/modules/github/display.go b/modules/github/display.go index 8d49d65d2..6a5d36318 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -16,14 +16,14 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n" - str = str + " [red]Stats[white]\n" - str = str + widget.displayStats(repo) - str = str + "\n" - str = str + " [red]Open Review Requests[white]\n" - str = str + widget.displayMyReviewRequests(repo, widget.settings.username) - str = str + "\n" - str = str + " [red]My Pull Requests[white]\n" - str = str + widget.displayMyPullRequests(repo, widget.settings.username) + str += " [red]Stats[white]\n" + str += widget.displayStats(repo) + str += "\n" + str += " [red]Open Review Requests[white]\n" + str += widget.displayMyReviewRequests(repo, widget.settings.username) + str += "\n" + str += " [red]My Pull Requests[white]\n" + str += widget.displayMyPullRequests(repo, widget.settings.username) widget.TextWidget.Redraw(title, str, false) } @@ -37,7 +37,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s str := "" for _, pr := range prs { - str = str + fmt.Sprintf(" %s[green]%4d[white] %s\n", widget.mergeString(pr), *pr.Number, *pr.Title) + str += fmt.Sprintf(" %s[green]%4d[white] %s\n", widget.mergeString(pr), *pr.Number, *pr.Title) } return str @@ -52,7 +52,7 @@ func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) str := "" for _, pr := range prs { - str = str + fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title) + str += fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title) } return str diff --git a/modules/gitlab/display.go b/modules/gitlab/display.go index 040bef5fc..ff1d9c804 100644 --- a/modules/gitlab/display.go +++ b/modules/gitlab/display.go @@ -16,14 +16,14 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GitlabProjects), widget.Idx, width) + "\n" - str = str + " [red]Stats[white]\n" - str = str + widget.displayStats(project) - str = str + "\n" - str = str + " [red]Open Approval Requests[white]\n" - str = str + widget.displayMyApprovalRequests(project, widget.settings.username) - str = str + "\n" - str = str + " [red]My Merge Requests[white]\n" - str = str + widget.displayMyMergeRequests(project, widget.settings.username) + str += " [red]Stats[white]\n" + str += widget.displayStats(project) + str += "\n" + str += " [red]Open Approval Requests[white]\n" + str += widget.displayMyApprovalRequests(project, widget.settings.username) + str += "\n" + str += " [red]My Merge Requests[white]\n" + str += widget.displayMyMergeRequests(project, widget.settings.username) widget.Redraw(title, str, false) } @@ -36,7 +36,7 @@ func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username st str := "" for _, mr := range mrs { - str = str + fmt.Sprintf(" [green]%4d[white] %s\n", mr.IID, mr.Title) + str += fmt.Sprintf(" [green]%4d[white] %s\n", mr.IID, mr.Title) } return str @@ -51,7 +51,7 @@ func (widget *Widget) displayMyApprovalRequests(project *GitlabProject, username str := "" for _, mr := range mrs { - str = str + fmt.Sprintf(" [green]%4d[white] %s\n", mr.IID, mr.Title) + str += fmt.Sprintf(" [green]%4d[white] %s\n", mr.IID, mr.Title) } return str diff --git a/modules/gitlab/widget.go b/modules/gitlab/widget.go index 542e09b37..adc725570 100644 --- a/modules/gitlab/widget.go +++ b/modules/gitlab/widget.go @@ -56,7 +56,7 @@ func (widget *Widget) Refresh() { } func (widget *Widget) Next() { - widget.Idx = widget.Idx + 1 + widget.Idx++ if widget.Idx == len(widget.GitlabProjects) { widget.Idx = 0 } @@ -65,7 +65,7 @@ func (widget *Widget) Next() { } func (widget *Widget) Prev() { - widget.Idx = widget.Idx - 1 + widget.Idx-- if widget.Idx < 0 { widget.Idx = len(widget.GitlabProjects) - 1 } diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 5adfc4b41..0c3d1afc6 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -83,7 +83,7 @@ func (widget *Widget) display() { func (widget *Widget) contentFrom(messages []Message) string { var str string for idx, message := range messages { - str = str + fmt.Sprintf( + str += fmt.Sprintf( `["%d"][%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s[""]`, idx, widget.RowColor(idx), @@ -94,7 +94,7 @@ func (widget *Widget) contentFrom(messages []Message) string { message.Sent.Format("Jan 02, 15:04 MST"), ) - str = str + "\n" + str += "\n" } return str diff --git a/modules/gspreadsheets/widget.go b/modules/gspreadsheets/widget.go index d17284746..45de4e718 100644 --- a/modules/gspreadsheets/widget.go +++ b/modules/gspreadsheets/widget.go @@ -43,7 +43,7 @@ func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string { cells := wtf.ToStrs(widget.settings.cellNames) for i := 0; i < len(valueRanges); i++ { - res = res + fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0]) + res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0]) } return res diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index a1506d865..50d4c82a2 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -83,7 +83,7 @@ func (widget *Widget) contentFrom(stories []Story) string { u, _ := url.Parse(story.URL) - str = str + fmt.Sprintf( + str += fmt.Sprintf( `["%d"][""][%s]%2d. %s [lightblue](%s)[white][""]`, idx, widget.RowColor(idx), @@ -92,7 +92,7 @@ func (widget *Widget) contentFrom(stories []Story) string { strings.TrimPrefix(u.Host, "www."), ) - str = str + "\n" + str += "\n" } return str diff --git a/modules/jenkins/client.go b/modules/jenkins/client.go index 7d7cfeb02..803d6b9b2 100644 --- a/modules/jenkins/client.go +++ b/modules/jenkins/client.go @@ -46,8 +46,8 @@ func (widget *Widget) Create(jenkinsURL string, username string, apiKey string) return view, nil } -func ensureLastSlash(URL string) string { - return strings.TrimRight(URL, "/") + "/" +func ensureLastSlash(url string) string { + return strings.TrimRight(url, "/") + "/" } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index 20187a76a..4d05b570b 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -75,7 +75,7 @@ func (widget *Widget) contentFrom(view *View) string { var validID = regexp.MustCompile(widget.settings.jobNameRegex) if validID.MatchString(job.Name) { - str = str + fmt.Sprintf( + str += fmt.Sprintf( `["%d"][%s] [%s]%-6s[white][""]`, idx, widget.RowColor(idx), @@ -83,7 +83,7 @@ func (widget *Widget) contentFrom(view *View) string { job.Name, ) - str = str + "\n" + str += "\n" } } diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 97db517d5..6ab1e0074 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -88,7 +88,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { ) _, _, w, _ := widget.View.GetInnerRect() - fmtStr = fmtStr + wtf.PadRow(len(issue.IssueFields.Summary), w+1) + fmtStr += wtf.PadRow(len(issue.IssueFields.Summary), w+1) str = str + fmtStr + "\n" } diff --git a/modules/logger/widget.go b/modules/logger/widget.go index 1a99965de..89972514a 100644 --- a/modules/logger/widget.go +++ b/modules/logger/widget.go @@ -52,7 +52,7 @@ func (widget *Widget) contentFrom(logLines []string) string { chunks := strings.Split(line, " ") if len(chunks) >= 4 { - str = str + fmt.Sprintf( + str += fmt.Sprintf( "[green]%s[white] [yellow]%s[white] %s\n", chunks[0], chunks[1], diff --git a/modules/mercurial/display.go b/modules/mercurial/display.go index 9ffbc3b0e..0baaae231 100644 --- a/modules/mercurial/display.go +++ b/modules/mercurial/display.go @@ -17,25 +17,24 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" - str = str + " [red]Branch:Bookmark[white]\n" - str = str + fmt.Sprintf(" %s:%s\n", repoData.Branch, repoData.Bookmark) - str = str + "\n" - str = str + widget.formatChanges(repoData.ChangedFiles) - str = str + "\n" - str = str + widget.formatCommits(repoData.Commits) + str += " [red]Branch:Bookmark[white]\n" + str += fmt.Sprintf(" %s:%s\n", repoData.Branch, repoData.Bookmark) + str += "\n" + str += widget.formatChanges(repoData.ChangedFiles) + str += "\n" + str += widget.formatCommits(repoData.Commits) widget.Redraw(title, str, false) } func (widget *Widget) formatChanges(data []string) string { - str := "" - str = str + " [red]Changed Files[white]\n" + str := " [red]Changed Files[white]\n" if len(data) == 1 { - str = str + " [grey]none[white]\n" + str += " [grey]none[white]\n" } else { for _, line := range data { - str = str + widget.formatChange(line) + str += widget.formatChange(line) } } @@ -66,11 +65,10 @@ func (widget *Widget) formatChange(line string) string { } func (widget *Widget) formatCommits(data []string) string { - str := "" - str = str + " [red]Recent Commits[white]\n" + str := " [red]Recent Commits[white]\n" for _, line := range data { - str = str + widget.formatCommit(line) + str += widget.formatCommit(line) } return str diff --git a/modules/nbascore/widget.go b/modules/nbascore/widget.go index a4a1867ad..0a74388f0 100644 --- a/modules/nbascore/widget.go +++ b/modules/nbascore/widget.go @@ -84,7 +84,8 @@ func (widget *Widget) nbascore() string { quarter := 0. activate := false for keyGame, team := range game.(map[string]interface{}) { // assertion - if keyGame == "vTeam" || keyGame == "hTeam" { + switch keyGame { + case "vTeam", "hTeam": for keyTeam, stat := range team.(map[string]interface{}) { if keyTeam == "triCode" { if keyGame == "vTeam" { @@ -100,13 +101,13 @@ func (widget *Widget) nbascore() string { } } } - } else if keyGame == "period" { + case "period": for keyTeam, stat := range team.(map[string]interface{}) { if keyTeam == "current" { quarter = stat.(float64) } } - } else if keyGame == "isGameActivated" { + case "isGameActivated": activate = team.(bool) } } @@ -114,16 +115,17 @@ func (widget *Widget) nbascore() string { hNum, _ := strconv.Atoi(hScore) hColor := "" if quarter != 0 { // Compare the score - if vNum > hNum { + switch { + case vNum > hNum: vTeam = "[orange]" + vTeam - } else if hNum > vNum { + case hNum > vNum: // hScore = "[orange]" + hScore hColor = "[orange]" // For correct padding - hTeam = hTeam + "[white]" - } else { + hTeam += "[white]" + default: vTeam = "[orange]" + vTeam hColor = "[orange]" - hTeam = hTeam + "[white]" + hTeam += "[white]" } } qColor := "[white]" diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 62d7d9719..edd1b7645 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -73,7 +73,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revLen = len(deploy.Revision) } - str = str + fmt.Sprintf( + str += fmt.Sprintf( " [green]%s[%s] %s %-.16s[white]\n", deploy.Revision[0:revLen], lineColor, diff --git a/modules/opsgenie/widget.go b/modules/opsgenie/widget.go index aef054453..96fee2af0 100644 --- a/modules/opsgenie/widget.go +++ b/modules/opsgenie/widget.go @@ -61,8 +61,8 @@ func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string { msg = fmt.Sprintf(" %s\n\n", strings.Join(wtf.NamesFromEmails(data.OnCallData.Recipients), ", ")) } - str = str + widget.cleanScheduleName(data.OnCallData.Parent.Name) - str = str + msg + str += widget.cleanScheduleName(data.OnCallData.Parent.Name) + str += msg } return str diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index 4741666f9..eebf411ba 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -48,10 +48,10 @@ func (widget *Widget) Refresh() { if err1 != nil || err2 != nil { wrap = true if err1 != nil { - content = content + err1.Error() + content += err1.Error() } if err2 != nil { - content = content + err2.Error() + content += err2.Error() } } else { widget.View.SetWrap(false) @@ -67,12 +67,12 @@ func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall, incidents []pagerd var str string if len(incidents) > 0 { - str = str + "[yellow]Incidents[white]\n" + str += "[yellow]Incidents[white]\n" for _, incident := range incidents { - str = str + fmt.Sprintf("[red]%s[white]\n", incident.Summary) - str = str + fmt.Sprintf("Status: %s\n", incident.Status) - str = str + fmt.Sprintf("Service: %s\n", incident.Service.Summary) - str = str + fmt.Sprintf("Escalation: %s\n", incident.EscalationPolicy.Summary) + str += fmt.Sprintf("[red]%s[white]\n", incident.Summary) + str += fmt.Sprintf("Status: %s\n", incident.Status) + str += fmt.Sprintf("Service: %s\n", incident.Service.Summary) + str += fmt.Sprintf("Escalation: %s\n", incident.EscalationPolicy.Summary) } } @@ -99,14 +99,14 @@ func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall, incidents []pagerd sort.Strings(keys) if len(keys) > 0 { - str = str + "\n[red] Schedules[white]\n" + str += "\n[red] Schedules[white]\n" // Print out policies, and escalation order of users for _, key := range keys { - str = str + fmt.Sprintf("\n [green::b]%s\n", key) + str += fmt.Sprintf("\n [green::b]%s\n", key) values := tree[key] sort.Sort(ByEscalationLevel(values)) for _, item := range values { - str = str + fmt.Sprintf(" [white]%d - %s\n", item.EscalationLevel, item.User.Summary) + str += fmt.Sprintf(" [white]%d - %s\n", item.EscalationLevel, item.User.Summary) } } } diff --git a/modules/power/battery_linux.go b/modules/power/battery_linux.go index 937631b3e..51db61233 100644 --- a/modules/power/battery_linux.go +++ b/modules/power/battery_linux.go @@ -69,12 +69,11 @@ func (battery *Battery) parse(data string) string { if s := table["time to empty"]; s == "" { table["time to empty"] = "∞" } - str := "" - str = str + fmt.Sprintf(" %10s: %s\n", "Charge", battery.formatCharge(table["percentage"])) - str = str + fmt.Sprintf(" %10s: %s\n", "Remaining", table["time to empty"]) - str = str + fmt.Sprintf(" %10s: %s\n", "State", battery.formatState(table["state"])) + str := fmt.Sprintf(" %10s: %s\n", "Charge", battery.formatCharge(table["percentage"])) + str += fmt.Sprintf(" %10s: %s\n", "Remaining", table["time to empty"]) + str += fmt.Sprintf(" %10s: %s\n", "State", battery.formatState(table["state"])) if s := table["time to full"]; s != "" { - str = str + fmt.Sprintf(" %10s: %s\n", "TimeToFull", table["time to full"]) + str += fmt.Sprintf(" %10s: %s\n", "TimeToFull", table["time to full"]) } batteryState = table["state"] return str diff --git a/modules/power/widget.go b/modules/power/widget.go index 0dfa167c2..5e9a4175f 100644 --- a/modules/power/widget.go +++ b/modules/power/widget.go @@ -32,10 +32,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.Battery.Refresh() - content := "" - content = content + fmt.Sprintf(" %10s: %s\n", "Source", powerSource()) - content = content + "\n" - content = content + widget.Battery.String() + content := fmt.Sprintf(" %10s: %s\n", "Source", powerSource()) + content += "\n" + content += widget.Battery.String() widget.Redraw(widget.CommonSettings.Title, content, true) } diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 7086be0ad..75dc00738 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -78,7 +78,7 @@ func (widget *Widget) contentFrom(result *Result) string { } for idx, item := range result.Items { - str = str + fmt.Sprintf( + str += fmt.Sprintf( "[%s] [%s] %s [%s] %s [%s]count: %d [%s]%s\n", widget.RowColor(idx), levelColor(&item), diff --git a/modules/security/widget.go b/modules/security/widget.go index 368aaa1f7..79d8cd451 100644 --- a/modules/security/widget.go +++ b/modules/security/widget.go @@ -42,23 +42,23 @@ func (widget *Widget) Refresh() { func (widget *Widget) contentFrom(data *SecurityData) string { str := " [red]WiFi[white]\n" - str = str + fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName) - str = str + fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption) - str = str + "\n" - - str = str + " [red]Firewall[white]\n" - str = str + fmt.Sprintf(" %8s: %4s\n", "Status", data.FirewallEnabled) - str = str + fmt.Sprintf(" %8s: %4s\n", "Stealth", data.FirewallStealth) - str = str + "\n" - - str = str + " [red]Users[white]\n" - str = str + fmt.Sprintf(" %s", strings.Join(data.LoggedInUsers, "\n ")) - str = str + "\n\n" - - str = str + " [red]DNS[white]\n" - str = str + fmt.Sprintf(" %12s\n", data.DnsAt(0)) - str = str + fmt.Sprintf(" %12s\n", data.DnsAt(1)) - str = str + "\n" + str += fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName) + str += fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption) + str += "\n" + + str += " [red]Firewall[white]\n" + str += fmt.Sprintf(" %8s: %4s\n", "Status", data.FirewallEnabled) + str += fmt.Sprintf(" %8s: %4s\n", "Stealth", data.FirewallStealth) + str += "\n" + + str += " [red]Users[white]\n" + str += fmt.Sprintf(" %s", strings.Join(data.LoggedInUsers, "\n ")) + str += "\n\n" + + str += " [red]DNS[white]\n" + str += fmt.Sprintf(" %12s\n", data.DnsAt(0)) + str += fmt.Sprintf(" %12s\n", data.DnsAt(1)) + str += "\n" return str } diff --git a/modules/security/wifi.go b/modules/security/wifi.go index 69a07a94d..3899adc4e 100644 --- a/modules/security/wifi.go +++ b/modules/security/wifi.go @@ -112,8 +112,7 @@ func parseWlanNetsh(target string) string { } } for i, token := range words { - switch token { - case target: + if token == target { return words[i+1] } } diff --git a/modules/status/widget.go b/modules/status/widget.go index e205dae84..5482cbe4f 100644 --- a/modules/status/widget.go +++ b/modules/status/widget.go @@ -37,7 +37,7 @@ func (widget *Widget) animation() string { icons := []string{"|", "/", "-", "\\", "|"} next := icons[widget.CurrentIcon] - widget.CurrentIcon = widget.CurrentIcon + 1 + widget.CurrentIcon++ if widget.CurrentIcon == len(icons) { widget.CurrentIcon = 0 } diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index 1a02ec108..00ce92282 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -76,9 +76,9 @@ func (widget *Widget) display() { text := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n" if widget.settings.format { - text = text + widget.formattedText() + text += widget.formattedText() } else { - text = text + widget.plainText() + text += widget.plainText() } widget.Redraw(title, text, true) diff --git a/modules/todo/display.go b/modules/todo/display.go index 179e81a3a..ae3071840 100644 --- a/modules/todo/display.go +++ b/modules/todo/display.go @@ -20,13 +20,13 @@ func (widget *Widget) display() { offset := 0 for idx, item := range widget.list.UncheckedItems() { - str = str + widget.formattedItemLine(idx, item, widget.list.SelectedItem(), widget.list.LongestLine()) + str += widget.formattedItemLine(idx, item, widget.list.SelectedItem(), widget.list.LongestLine()) newList.Items = append(newList.Items, item) offset++ } for idx, item := range widget.list.CheckedItems() { - str = str + widget.formattedItemLine(idx+offset, item, widget.list.SelectedItem(), widget.list.LongestLine()) + str += widget.formattedItemLine(idx+offset, item, widget.list.SelectedItem(), widget.list.LongestLine()) newList.Items = append(newList.Items, item) } diff --git a/modules/todoist/project.go b/modules/todoist/project.go index 7c52fa9f3..1f1f6863a 100644 --- a/modules/todoist/project.go +++ b/modules/todoist/project.go @@ -14,12 +14,12 @@ type Project struct { } func NewProject(id int) *Project { - // Todoist seems to experience a lot of network issues on their side - // If we can't connect, handle it with an empty project until we can + // Todoist seems to experience a lot of network issues on their side + // If we can't connect, handle it with an empty project until we can project, err := todoist.GetProject(id) - if err != nil { - return &Project{} - } + if err != nil { + return &Project{} + } proj := &Project{ Project: project, @@ -41,7 +41,7 @@ func (proj *Project) isLast() bool { } func (proj *Project) up() { - proj.index = proj.index - 1 + proj.index-- if proj.index < 0 { proj.index = len(proj.tasks) - 1 @@ -54,7 +54,7 @@ func (proj *Project) down() { return } - proj.index = proj.index + 1 + proj.index++ if proj.index >= len(proj.tasks) { proj.index = 0 } diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index 8bce6ade1..5413fa14a 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -66,7 +66,7 @@ func (widget *Widget) contentFrom(builds *Builds) string { var str string for idx, build := range builds.Builds { - str = str + fmt.Sprintf( + str += fmt.Sprintf( "[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n", widget.RowColor(idx), buildColor(&build), diff --git a/modules/trello/client.go b/modules/trello/client.go index f3bb451cb..e010ce1b7 100644 --- a/modules/trello/client.go +++ b/modules/trello/client.go @@ -26,7 +26,7 @@ func GetCards(client *trello.Client, username string, boardName string, lists ma return nil, err } - searchResult.Total = searchResult.Total + len(cards) + searchResult.Total += len(cards) cardArray := make([]TrelloCard, 0) for _, card := range cards { diff --git a/modules/trello/widget.go b/modules/trello/widget.go index d967aea05..4f63d2cc0 100644 --- a/modules/trello/widget.go +++ b/modules/trello/widget.go @@ -67,10 +67,10 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { str := "" for list, cardArray := range searchResult.TrelloCards { - str = str + fmt.Sprintf(" [red]%s[white]\n", list) + str += fmt.Sprintf(" [red]%s[white]\n", list) for _, card := range cardArray { - str = str + fmt.Sprintf(" %s[white]\n", card.Name) + str += fmt.Sprintf(" %s[white]\n", card.Name) } str = fmt.Sprintf("%s\n", str) } diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index 446546f27..b26ae2107 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -75,7 +75,7 @@ func (widget *Widget) display() { _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width-2) + "\n" for _, tweet := range tweets { - str = str + widget.format(tweet) + str += widget.format(tweet) } widget.Redraw(title, str, true) diff --git a/modules/weatherservices/weather/display.go b/modules/weatherservices/weather/display.go index 85e72f7dc..1659612b2 100644 --- a/modules/weatherservices/weather/display.go +++ b/modules/weatherservices/weather/display.go @@ -35,9 +35,9 @@ func (widget *Widget) display() { title = widget.buildTitle(cityData) _, _, width, _ := widget.View.GetRect() content = widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" - content = content + widget.description(cityData) + "\n\n" - content = content + widget.temperatures(cityData) + "\n" - content = content + widget.sunInfo(cityData) + content += widget.description(cityData) + "\n\n" + content += widget.temperatures(cityData) + "\n" + content += widget.sunInfo(cityData) } widget.Redraw(title, content, setWrap) @@ -63,7 +63,7 @@ func (widget *Widget) sunInfo(cityData *owm.CurrentWeatherData) string { func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string { str := fmt.Sprintf("%8s: %4.1f° %s\n", "High", cityData.Main.TempMax, widget.settings.tempUnit) - str = str + fmt.Sprintf( + str += fmt.Sprintf( "%8s: [%s]%4.1f° %s[white]\n", "Current", widget.settings.colors.current, @@ -71,7 +71,7 @@ func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string { widget.settings.tempUnit, ) - str = str + fmt.Sprintf("%8s: %4.1f° %s\n", "Low", cityData.Main.TempMin, widget.settings.tempUnit) + str += fmt.Sprintf("%8s: %4.1f° %s\n", "Low", cityData.Main.TempMin, widget.settings.tempUnit) return str } diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index 6f8f80ead..a19ad7380 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -68,7 +68,7 @@ func (widget *Widget) Refresh() { // Next displays data for the next city data in the list. If the current city is the last // city, it wraps to the first city. func (widget *Widget) Next() { - widget.Idx = widget.Idx + 1 + widget.Idx++ if widget.Idx == len(widget.Data) { widget.Idx = 0 } @@ -79,7 +79,7 @@ func (widget *Widget) Next() { // Prev displays data for the previous city in the list. If the previous city is the first // city, it wraps to the last city. func (widget *Widget) Prev() { - widget.Idx = widget.Idx - 1 + widget.Idx-- if widget.Idx < 0 { widget.Idx = len(widget.Data) - 1 } diff --git a/modules/zendesk/widget.go b/modules/zendesk/widget.go index cd05a60aa..307009762 100644 --- a/modules/zendesk/widget.go +++ b/modules/zendesk/widget.go @@ -63,7 +63,7 @@ func (widget *Widget) textContent(items []Ticket) string { str := "" for idx, data := range items { - str = str + widget.format(data, idx) + str += widget.format(data, idx) } return str diff --git a/wtf/billboard_modal.go b/wtf/billboard_modal.go index fedc8e6de..6a80fd283 100644 --- a/wtf/billboard_modal.go +++ b/wtf/billboard_modal.go @@ -11,8 +11,7 @@ const modalHeight = 22 func NewBillboardModal(text string, closeFunc func()) *tview.Frame { keyboardIntercept := func(event *tcell.EventKey) *tcell.EventKey { - switch string(event.Rune()) { - case "/": + if string(event.Rune()) == "/" { closeFunc() return nil } diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index de935c969..d5417e027 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -152,7 +152,7 @@ func (tracker *FocusTracker) blur(idx int) { } func (tracker *FocusTracker) decrement() { - tracker.Idx = tracker.Idx - 1 + tracker.Idx-- if tracker.Idx < 0 { tracker.Idx = len(tracker.focusables()) - 1 @@ -216,7 +216,7 @@ func (tracker *FocusTracker) focusState() FocusState { } func (tracker *FocusTracker) increment() { - tracker.Idx = tracker.Idx + 1 + tracker.Idx++ if tracker.Idx == len(tracker.focusables()) { tracker.Idx = 0 diff --git a/wtf/keyboard_widget.go b/wtf/keyboard_widget.go index aebe85e97..317d60fb5 100644 --- a/wtf/keyboard_widget.go +++ b/wtf/keyboard_widget.go @@ -89,12 +89,12 @@ func (widget *KeyboardWidget) HelpText() string { str := "Keyboard commands for " + widget.settings.Module.Type + "\n\n" for _, item := range widget.charHelp { - str = str + fmt.Sprintf(" [%s]: %s\n", item.Key, item.Text) + str += fmt.Sprintf(" [%s]: %s\n", item.Key, item.Text) } - str = str + "\n\n" + str += "\n\n" for _, item := range widget.keyHelp { - str = str + fmt.Sprintf(" [%-*s]: %s\n", widget.maxKey, item.Key, item.Text) + str += fmt.Sprintf(" [%-*s]: %s\n", widget.maxKey, item.Key, item.Text) } return str diff --git a/wtf/multisource_widget.go b/wtf/multisource_widget.go index 54ff9ff3b..ae83b0f02 100644 --- a/wtf/multisource_widget.go +++ b/wtf/multisource_widget.go @@ -45,7 +45,7 @@ func (widget *MultiSourceWidget) CurrentSource() string { // Next displays the next source in the source list. If the current source is the last // source it wraps around to the first source func (widget *MultiSourceWidget) NextSource() { - widget.Idx = widget.Idx + 1 + widget.Idx++ if widget.Idx == len(widget.Sources) { widget.Idx = 0 } @@ -58,7 +58,7 @@ func (widget *MultiSourceWidget) NextSource() { // Prev displays the previous source in the source list. If the current source is the first // source, it wraps around to the last source func (widget *MultiSourceWidget) PrevSource() { - widget.Idx = widget.Idx - 1 + widget.Idx-- if widget.Idx < 0 { widget.Idx = len(widget.Sources) - 1 }