1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add a helper function to do highlighting in a uniform way

This commit is contained in:
Sean Smith 2019-05-24 22:06:07 -04:00
parent a06cbcbd7f
commit c4d58ece81
10 changed files with 36 additions and 51 deletions

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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))
}
}

View File

@ -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

View File

@ -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

View File

@ -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))
}

View File

@ -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)

View File

@ -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

View File

@ -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
}