8000 Add a helper function to do highlighting in a uniform way by Seanstoppable · Pull Request #465 · wtfutil/wtf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a helper function to do highlighting in a uniform way #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
6 changes: 3 additions & 3 deletions modules/datadog/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions modules/gitter/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions modules/hackernews/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions modules/jenkins/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
10 changes: 3 additions & 7 deletions modules/jira/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions modules/rollbar/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
14 changes: 3 additions & 11 deletions modules/todo/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/wtfutil/wtf/wtf"
)

const checkWidth = 4

func (widget *Widget) display() {
str := ""
newList := checklist.NewChecklist(
Expand Down Expand Up @@ -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))
}
18 changes: 3 additions & 15 deletions modules/todoist/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/wtfutil/wtf/wtf"
)

const checkWidth = 4

func (widget *Widget) display() {
proj := widget.CurrentProject()

Expand All @@ -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 F438 ) + "\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)
Expand Down
3 changes: 2 additions & 1 deletion modules/travisci/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions wtf/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"strings"

"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
)

Expand Down Expand Up @@ -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
}
0