Skip to content

Commit

Permalink
Merge pull request #460 from sosiska/patch-1
Browse files Browse the repository at this point in the history
Some code improvements
  • Loading branch information
senorprogrammer authored May 22, 2019
2 parents c050292 + f0771cd commit 0c0c6e9
Show file tree
Hide file tree
Showing 46 changed files with 164 additions and 171 deletions.
4 changes: 2 additions & 2 deletions cfg/common_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
}
Expand Down
4 changes: 2 additions & 2 deletions checklist/checklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ 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
}
}

// 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
}
Expand Down
2 changes: 1 addition & 1 deletion modules/bamboohr/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/circleci/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion modules/clocks/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions modules/cryptoexchanges/blockfolio/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions modules/datadog/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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]",
)
Expand All @@ -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]",
)
Expand Down
4 changes: 2 additions & 2 deletions modules/gcal/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions modules/gerrit/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/gerrit/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
24 changes: 11 additions & 13 deletions modules/git/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions modules/github/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions modules/gitlab/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/gitlab/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gitter/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/gspreadsheets/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/hackernews/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -92,7 +92,7 @@ func (widget *Widget) contentFrom(stories []Story) string {
strings.TrimPrefix(u.Host, "www."),
)

str = str + "\n"
str += "\n"
}

return str
Expand Down
4 changes: 2 additions & 2 deletions modules/jenkins/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------- */
Expand Down
Loading

0 comments on commit 0c0c6e9

Please sign in to comment.