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:
parent
a06cbcbd7f
commit
c4d58ece81
@ -78,12 +78,12 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
|
|||||||
"[red]Triggered Monitors[white]",
|
"[red]Triggered Monitors[white]",
|
||||||
)
|
)
|
||||||
for idx, triggeredMonitor := range triggeredMonitors {
|
for idx, triggeredMonitor := range triggeredMonitors {
|
||||||
str = str + fmt.Sprintf(`["%d"][%s][red] %s[%s][""]`,
|
row := fmt.Sprintf(`[%s][red] %s[%s]`,
|
||||||
idx,
|
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
*triggeredMonitor.Name,
|
*triggeredMonitor.Name,
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
) + "\n"
|
)
|
||||||
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str += fmt.Sprintf(
|
str += fmt.Sprintf(
|
||||||
|
@ -83,9 +83,8 @@ func (widget *Widget) display() {
|
|||||||
func (widget *Widget) contentFrom(messages []Message) string {
|
func (widget *Widget) contentFrom(messages []Message) string {
|
||||||
var str string
|
var str string
|
||||||
for idx, message := range messages {
|
for idx, message := range messages {
|
||||||
str += fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s[""]`,
|
`[%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s`,
|
||||||
idx,
|
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
message.From.DisplayName,
|
message.From.DisplayName,
|
||||||
message.From.Username,
|
message.From.Username,
|
||||||
@ -94,7 +93,7 @@ func (widget *Widget) contentFrom(messages []Message) string {
|
|||||||
message.Sent.Format("Jan 02, 15:04 MST"),
|
message.Sent.Format("Jan 02, 15:04 MST"),
|
||||||
)
|
)
|
||||||
|
|
||||||
str += "\n"
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(message.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
|
@ -83,16 +83,15 @@ func (widget *Widget) contentFrom(stories []Story) string {
|
|||||||
|
|
||||||
u, _ := url.Parse(story.URL)
|
u, _ := url.Parse(story.URL)
|
||||||
|
|
||||||
str += fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][""][%s]%2d. %s [lightblue](%s)[white][""]`,
|
`[%s]%2d. %s [lightblue](%s)[white]`,
|
||||||
idx,
|
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
idx+1,
|
idx+1,
|
||||||
story.Title,
|
story.Title,
|
||||||
strings.TrimPrefix(u.Host, "www."),
|
strings.TrimPrefix(u.Host, "www."),
|
||||||
)
|
)
|
||||||
|
|
||||||
str += "\n"
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(story.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
|
@ -75,15 +75,14 @@ func (widget *Widget) contentFrom(view *View) string {
|
|||||||
var validID = regexp.MustCompile(widget.settings.jobNameRegex)
|
var validID = regexp.MustCompile(widget.settings.jobNameRegex)
|
||||||
|
|
||||||
if validID.MatchString(job.Name) {
|
if validID.MatchString(job.Name) {
|
||||||
str += fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][%s] [%s]%-6s[white][""]`,
|
`[%s] [%s]%-6s[white]`,
|
||||||
idx,
|
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
widget.jobColor(&job),
|
widget.jobColor(&job),
|
||||||
job.Name,
|
job.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
str += "\n"
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(job.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,8 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|||||||
str := " [red]Assigned Issues[white]\n"
|
str := " [red]Assigned Issues[white]\n"
|
||||||
|
|
||||||
for idx, issue := range searchResult.Issues {
|
for idx, issue := range searchResult.Issues {
|
||||||
fmtStr := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s[""]`,
|
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
|
||||||
idx,
|
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
widget.issueTypeColor(&issue),
|
widget.issueTypeColor(&issue),
|
||||||
issue.IssueFields.IssueType.Name,
|
issue.IssueFields.IssueType.Name,
|
||||||
@ -87,10 +86,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|||||||
issue.IssueFields.Summary,
|
issue.IssueFields.Summary,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, _, w, _ := widget.View.GetInnerRect()
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
|
||||||
fmtStr += wtf.PadRow(len(issue.IssueFields.Summary), w+1)
|
|
||||||
|
|
||||||
str = str + fmtStr + "\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
|
@ -78,8 +78,8 @@ func (widget *Widget) contentFrom(result *Result) string {
|
|||||||
}
|
}
|
||||||
for idx, item := range result.Items {
|
for idx, item := range result.Items {
|
||||||
|
|
||||||
str += fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
"[%s] [%s] %s [%s] %s [%s]count: %d [%s]%s\n",
|
"[%s] [%s] %s [%s] %s [%s]count: %d [%s]%s",
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
levelColor(&item),
|
levelColor(&item),
|
||||||
item.Level,
|
item.Level,
|
||||||
@ -90,6 +90,7 @@ func (widget *Widget) contentFrom(result *Result) string {
|
|||||||
"blue",
|
"blue",
|
||||||
item.Environment,
|
item.Environment,
|
||||||
)
|
)
|
||||||
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(item.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
|
@ -8,8 +8,6 @@ import (
|
|||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
const checkWidth = 4
|
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
str := ""
|
str := ""
|
||||||
newList := checklist.NewChecklist(
|
newList := checklist.NewChecklist(
|
||||||
@ -48,19 +46,13 @@ func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem,
|
|||||||
backColor = widget.settings.common.Colors.HighlightBack
|
backColor = widget.settings.common.Colors.HighlightBack
|
||||||
}
|
}
|
||||||
|
|
||||||
str := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][""][%s:%s]|%s| %s[white][""]`,
|
` [%s:%s]|%s| %s[white]`,
|
||||||
idx,
|
|
||||||
foreColor,
|
foreColor,
|
||||||
backColor,
|
backColor,
|
||||||
item.CheckMark(),
|
item.CheckMark(),
|
||||||
tview.Escape(item.Text),
|
tview.Escape(item.Text),
|
||||||
)
|
)
|
||||||
|
|
||||||
_, _, w, _ := widget.View.GetInnerRect()
|
return wtf.HighlightableHelper(widget.View, row, idx, len(item.Text))
|
||||||
if w > maxLen {
|
|
||||||
maxLen = w
|
|
||||||
}
|
|
||||||
|
|
||||||
return str + wtf.PadRow((checkWidth+len(item.Text)), (checkWidth+maxLen+1)) + "\n"
|
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
const checkWidth = 4
|
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
proj := widget.CurrentProject()
|
proj := widget.CurrentProject()
|
||||||
|
|
||||||
@ -17,27 +15,17 @@ func (widget *Widget) display() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
|
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
|
||||||
|
str := ""
|
||||||
_, _, width, _ := widget.View.GetRect()
|
|
||||||
str := widget.settings.common.SigilStr(len(widget.projects), widget.Idx, width) + "\n"
|
|
||||||
|
|
||||||
maxLen := proj.LongestLine()
|
|
||||||
|
|
||||||
for index, item := range proj.tasks {
|
for index, item := range proj.tasks {
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`["%d"][""][%s]| | %s[%s]`,
|
`[%s]| | %s[%s]`,
|
||||||
index,
|
|
||||||
widget.RowColor(index),
|
widget.RowColor(index),
|
||||||
tview.Escape(item.Content),
|
tview.Escape(item.Content),
|
||||||
widget.RowColor(index),
|
widget.RowColor(index),
|
||||||
)
|
)
|
||||||
|
|
||||||
_, _, w, _ := widget.View.GetInnerRect()
|
str += wtf.HighlightableHelper(widget.View, row, index, len(item.Content))
|
||||||
if w > maxLen {
|
|
||||||
maxLen = w
|
|
||||||
}
|
|
||||||
|
|
||||||
str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + `[""]` + "\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.ScrollableWidget.Redraw(title, str, false)
|
widget.ScrollableWidget.Redraw(title, str, false)
|
||||||
|
@ -66,7 +66,7 @@ func (widget *Widget) contentFrom(builds *Builds) string {
|
|||||||
var str string
|
var str string
|
||||||
for idx, build := range builds.Builds {
|
for idx, build := range builds.Builds {
|
||||||
|
|
||||||
str += fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
buildColor(&build),
|
buildColor(&build),
|
||||||
@ -77,6 +77,7 @@ func (widget *Widget) contentFrom(builds *Builds) string {
|
|||||||
strings.Split(build.Commit.Message, "\n")[0],
|
strings.Split(build.Commit.Message, "\n")[0],
|
||||||
build.CreatedBy.Login,
|
build.CreatedBy.Login,
|
||||||
)
|
)
|
||||||
|
str += wtf.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
|
10
wtf/utils.go
10
wtf/utils.go
@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -198,3 +199,12 @@ func ToStrs(slice []interface{}) []string {
|
|||||||
|
|
||||||
return results
|
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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user