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

Fix race with HighlightableHelper

GetRect can lead to a race condition
Add a RenderFunc method so that we can call try to
wrap even more of our rendering in the thread safe
`QueueUpdateDraw` method
This commit is contained in:
Sean Smith 2019-08-24 22:05:37 -04:00
parent 3f5fe6f3e5
commit 264f49fd2c
12 changed files with 69 additions and 45 deletions

View File

@ -60,8 +60,7 @@ func (widget *Widget) Refresh() {
}
func (widget *Widget) Render() {
content := widget.contentFrom(widget.monitors)
widget.Redraw(widget.CommonSettings().Title, content, false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) HelpText() string {
@ -70,7 +69,8 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
func (widget *Widget) content() (string, string, bool) {
triggeredMonitors := widget.monitors
var str string
if len(triggeredMonitors) > 0 {
@ -93,7 +93,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
)
}
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) openItem() {

View File

@ -91,8 +91,7 @@ func (widget *Widget) Render() {
return
}
title := widget.CommonSettings().Title
widget.Redraw(title, widget.contentFrom(widget.stories), false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
@ -123,7 +122,9 @@ func (widget *Widget) fetchForFeed(feedURL string) ([]*FeedItem, error) {
return feedItems, nil
}
func (widget *Widget) contentFrom(data []*FeedItem) string {
func (widget *Widget) content() (string, string, bool) {
data := widget.stories
title := widget.CommonSettings().Title
var str string
for idx, feedItem := range data {
@ -147,7 +148,7 @@ func (widget *Widget) contentFrom(data []*FeedItem) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(feedItem.item.Title))
}
return str
return title, str, true
}
// feedItems are sorted by published date

View File

@ -76,14 +76,13 @@ func (widget *Widget) display() {
return
}
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.roomURI)
widget.Redraw(title, widget.contentFrom(widget.messages), true)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) contentFrom(messages []Message) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.roomURI)
var str string
for idx, message := range messages {
for idx, message := range widget.messages {
row := fmt.Sprintf(
`[%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s`,
widget.RowColor(idx),
@ -97,7 +96,7 @@ func (widget *Widget) contentFrom(messages []Message) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(message.Text))
}
return str
return title, str, true
}
func (widget *Widget) openMessage() {

View File

@ -71,13 +71,14 @@ func (widget *Widget) Render() {
return
}
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
widget.Redraw(title, widget.contentFrom(widget.stories), false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(stories []Story) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
stories := widget.stories
var str string
for idx, story := range stories {
@ -94,7 +95,7 @@ func (widget *Widget) contentFrom(stories []Story) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(story.Title))
}
return str
return title, str, false
}
func (widget *Widget) openStory() {

View File

@ -2,7 +2,6 @@ package jenkins
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view"
@ -64,14 +63,15 @@ func (widget *Widget) Render() {
return
}
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
widget.Redraw(title, widget.contentFrom(widget.view), false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) contentFrom(view *View) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
var str string
for idx, job := range view.Jobs {
jobs := widget.view.Jobs
for idx, job := range jobs {
row := fmt.Sprintf(
`[%s] [%s]%-6s[white]`,
@ -83,7 +83,7 @@ func (widget *Widget) contentFrom(view *View) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(job.Name))
}
return str
return title, str, false
}
func (widget *Widget) jobColor(job *Job) string {

View File

@ -65,13 +65,14 @@ func (widget *Widget) Render() {
return
}
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
widget.Redraw(title, widget.contentFrom(widget.items), false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) contentFrom(result *Result) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
result := widget.items
if result == nil {
return "No results"
return title, "No results", false
}
var str string
if len(result.Items) > widget.settings.count {
@ -94,7 +95,7 @@ func (widget *Widget) contentFrom(result *Result) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Title))
}
return str
return title, str, false
}
func statusColor(item *Item) string {

View File

@ -9,6 +9,10 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
str := ""
newList := checklist.NewChecklist(
widget.settings.common.Sigils.Checkbox.Checked,
@ -31,7 +35,7 @@ func (widget *Widget) display() {
newList.SetSelectedByItem(widget.list.SelectedItem())
widget.SetList(newList)
widget.Redraw(widget.CommonSettings().Title, str, false)
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {

View File

@ -7,14 +7,15 @@ import (
"github.com/wtfutil/wtf/utils"
)
func (widget *Widget) display() {
func (widget *Widget) content() (string, string, bool) {
proj := widget.CurrentProject()
if proj == nil {
return
return widget.CommonSettings().Title, "", false
}
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
str := ""
for idx, item := range proj.tasks {
@ -27,6 +28,9 @@ func (widget *Widget) display() {
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Content))
}
widget.ScrollableWidget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) display() {
widget.ScrollableWidget.RedrawFunc(widget.content)
}

View File

@ -9,7 +9,8 @@ import (
"github.com/wtfutil/wtf/utils"
)
func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
func (widget *Widget) content() (string, string, bool) {
data := widget.torrents
str := ""
for idx, torrent := range data {
@ -27,12 +28,11 @@ func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
}
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) display() {
content := widget.contentFrom(widget.torrents)
widget.ScrollableWidget.Redraw(widget.CommonSettings().Title, content, false)
widget.ScrollableWidget.RedrawFunc(widget.content)
}
func (widget *Widget) prettyTorrentName(name string) string {

View File

@ -59,13 +59,13 @@ func (widget *Widget) Render() {
return
}
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
widget.Redraw(title, widget.contentFrom(widget.builds), false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) contentFrom(builds *Builds) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
var str string
for idx, build := range builds.Builds {
for idx, build := range widget.builds.Builds {
row := fmt.Sprintf(
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
@ -81,7 +81,7 @@ func (widget *Widget) contentFrom(builds *Builds) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
}
return str
return title, str, false
}
func buildColor(build *Build) string {

View File

@ -9,6 +9,10 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
var err string
if widget.apiKeyValid() == false {
@ -40,7 +44,7 @@ func (widget *Widget) display() {
content += widget.sunInfo(cityData)
}
widget.Redraw(title, content, setWrap)
return title, content, setWrap
}
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {

View File

@ -38,6 +38,16 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) {
})
}
func (widget *TextWidget) RedrawFunc(data func() (string, string, bool)) {
widget.app.QueueUpdateDraw(func() {
title, content, wrap := data()
widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(content)
})
}
/* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) createView(bordered bool) *tview.TextView {