diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index d1b6142a..f6afaeb5 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -78,12 +78,12 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string { "[red]Triggered Monitors[white]", ) for idx, triggeredMonitor := range triggeredMonitors { - str = str + fmt.Sprintf(`["%d"][%s][red] %s[%s][""]`, - idx, + row := fmt.Sprintf(`[%s][red] %s[%s]`, widget.RowColor(idx), *triggeredMonitor.Name, widget.RowColor(idx), - ) + "\n" + ) + str += wtf.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name)) } } else { str += fmt.Sprintf( diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 0c3d1afc..15517f10 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -83,9 +83,8 @@ func (widget *Widget) display() { func (widget *Widget) contentFrom(messages []Message) string { var str string for idx, message := range messages { - str += fmt.Sprintf( - `["%d"][%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s[""]`, - idx, + row := fmt.Sprintf( + `[%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s`, widget.RowColor(idx), message.From.DisplayName, message.From.Username, @@ -94,7 +93,7 @@ func (widget *Widget) contentFrom(messages []Message) string { message.Sent.Format("Jan 02, 15:04 MST"), ) - str += "\n" + str += wtf.HighlightableHelper(widget.View, row, idx, len(message.Text)) } return str diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index 50d4c82a..daa49f9b 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -83,16 +83,15 @@ func (widget *Widget) contentFrom(stories []Story) string { u, _ := url.Parse(story.URL) - str += fmt.Sprintf( - `["%d"][""][%s]%2d. %s [lightblue](%s)[white][""]`, - idx, + row := fmt.Sprintf( + `[%s]%2d. %s [lightblue](%s)[white]`, widget.RowColor(idx), idx+1, story.Title, strings.TrimPrefix(u.Host, "www."), ) - str += "\n" + str += wtf.HighlightableHelper(widget.View, row, idx, len(story.Title)) } return str diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index 4d05b570..01f1b018 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -75,15 +75,14 @@ func (widget *Widget) contentFrom(view *View) string { var validID = regexp.MustCompile(widget.settings.jobNameRegex) if validID.MatchString(job.Name) { - str += fmt.Sprintf( - `["%d"][%s] [%s]%-6s[white][""]`, - idx, + row := fmt.Sprintf( + `[%s] [%s]%-6s[white]`, widget.RowColor(idx), widget.jobColor(&job), job.Name, ) - str += "\n" + str += wtf.HighlightableHelper(widget.View, row, idx, len(job.Name)) } } diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 6ab1e007..d457259d 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -75,9 +75,8 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { str := " [red]Assigned Issues[white]\n" for idx, issue := range searchResult.Issues { - fmtStr := fmt.Sprintf( - `["%d"][%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s[""]`, - idx, + row := fmt.Sprintf( + `[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`, widget.RowColor(idx), widget.issueTypeColor(&issue), issue.IssueFields.IssueType.Name, @@ -87,10 +86,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { issue.IssueFields.Summary, ) - _, _, w, _ := widget.View.GetInnerRect() - fmtStr += wtf.PadRow(len(issue.IssueFields.Summary), w+1) - - str = str + fmtStr + "\n" + str += wtf.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary)) } return str diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 75dc0073..ad055181 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -78,8 +78,8 @@ func (widget *Widget) contentFrom(result *Result) string { } for idx, item := range result.Items { - str += fmt.Sprintf( - "[%s] [%s] %s [%s] %s [%s]count: %d [%s]%s\n", + row := fmt.Sprintf( + "[%s] [%s] %s [%s] %s [%s]count: %d [%s]%s", widget.RowColor(idx), levelColor(&item), item.Level, @@ -90,6 +90,7 @@ func (widget *Widget) contentFrom(result *Result) string { "blue", item.Environment, ) + str += wtf.HighlightableHelper(widget.View, row, idx, len(item.Title)) } return str diff --git a/modules/todo/display.go b/modules/todo/display.go index ae307184..9d083ab0 100644 --- a/modules/todo/display.go +++ b/modules/todo/display.go @@ -8,8 +8,6 @@ import ( "github.com/wtfutil/wtf/wtf" ) -const checkWidth = 4 - func (widget *Widget) display() { str := "" newList := checklist.NewChecklist( @@ -48,19 +46,13 @@ func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, backColor = widget.settings.common.Colors.HighlightBack } - str := fmt.Sprintf( - `["%d"][""][%s:%s]|%s| %s[white][""]`, - idx, + row := fmt.Sprintf( + ` [%s:%s]|%s| %s[white]`, foreColor, backColor, item.CheckMark(), tview.Escape(item.Text), ) - _, _, w, _ := widget.View.GetInnerRect() - if w > maxLen { - maxLen = w - } - - return str + wtf.PadRow((checkWidth+len(item.Text)), (checkWidth+maxLen+1)) + "\n" + return wtf.HighlightableHelper(widget.View, row, idx, len(item.Text)) } diff --git a/modules/todoist/display.go b/modules/todoist/display.go index f07758b3..e88fcaab 100644 --- a/modules/todoist/display.go +++ b/modules/todoist/display.go @@ -7,8 +7,6 @@ import ( "github.com/wtfutil/wtf/wtf" ) -const checkWidth = 4 - func (widget *Widget) display() { proj := widget.CurrentProject() @@ -17,27 +15,17 @@ func (widget *Widget) display() { } title := fmt.Sprintf("[green]%s[white]", proj.Project.Name) - - _, _, width, _ := widget.View.GetRect() - str := widget.settings.common.SigilStr(len(widget.projects), widget.Idx, width) + "\n" - - maxLen := proj.LongestLine() + str := "" for index, item := range proj.tasks { row := fmt.Sprintf( - `["%d"][""][%s]| | %s[%s]`, - index, + `[%s]| | %s[%s]`, widget.RowColor(index), tview.Escape(item.Content), widget.RowColor(index), ) - _, _, w, _ := widget.View.GetInnerRect() - if w > maxLen { - maxLen = w - } - - str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + `[""]` + "\n" + str += wtf.HighlightableHelper(widget.View, row, index, len(item.Content)) } widget.ScrollableWidget.Redraw(title, str, false) diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index 5413fa14..13bac723 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 += fmt.Sprintf( + row := fmt.Sprintf( "[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n", widget.RowColor(idx), buildColor(&build), @@ -77,6 +77,7 @@ func (widget *Widget) contentFrom(builds *Builds) string { strings.Split(build.Commit.Message, "\n")[0], build.CreatedBy.Login, ) + str += wtf.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name)) } return str diff --git a/wtf/utils.go b/wtf/utils.go index 4ac6dbe3..c4a2512c 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" + "github.com/rivo/tview" "github.com/wtfutil/wtf/utils" ) @@ -198,3 +199,12 @@ func ToStrs(slice []interface{}) []string { return results } + +func HighlightableHelper(view *tview.TextView, input string, idx, offset int) string { + fmtStr := fmt.Sprintf(`["%d"][""]`, idx) + _, _, w, _ := view.GetInnerRect() + fmtStr += input + fmtStr += PadRow(offset, w+1) + fmtStr += `[""]` + "\n" + return fmtStr +}