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

Add a global Redraw method for TextWidget

Partially addresses #429, by centralizing widget drawing
This commit is contained in:
Sean Smith
2019-05-07 20:49:46 -04:00
committed by Chris Cummer
parent aedcf9dd51
commit 018d2af3ae
48 changed files with 194 additions and 412 deletions

View File

@@ -2,7 +2,6 @@ package jira
import (
"fmt"
"strconv"
"github.com/rivo/tview"
@@ -27,7 +26,8 @@ type Widget struct {
wtf.KeyboardWidget
wtf.TextWidget
app *tview.Application
app *tview.Application
result *SearchResult
selected int
settings *Settings
@@ -67,19 +67,11 @@ func (widget *Widget) Refresh() {
if err != nil {
widget.result = nil
widget.View.SetWrap(true)
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.CommonSettings.Title)
widget.View.SetText(err.Error())
})
} else {
widget.result = searchResult
widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
return
}
widget.app.QueueUpdateDraw(func() {
widget.display()
})
widget.result = searchResult
widget.display()
}
/* -------------------- Unexported Functions -------------------- */
@@ -88,14 +80,13 @@ func (widget *Widget) display() {
if widget.result == nil {
return
}
widget.View.SetWrap(false)
str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings.Title, widget.settings.projects)
widget.View.Clear()
widget.View.SetTitle(widget.ContextualTitle(str))
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result)))
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
widget.Redraw(str, widget.contentFrom(widget.result), false)
widget.app.QueueUpdateDraw(func() {
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
})
}
func (widget *Widget) next() {