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

Renormalize the redraw function

Have all instances take a function
Update the remaining modules to take this into account
Numerous smaller refactors to make some widgets work more or less the same
This commit is contained in:
Sean Smith 2019-08-27 21:51:37 -04:00
parent 67658e172c
commit 14e7619075
53 changed files with 209 additions and 182 deletions

View File

@ -44,7 +44,7 @@ func (widget *Widget) Refresh() {
time.Now().Local().Format(wtf.DateFormat),
)
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -32,7 +32,7 @@ func (widget *Widget) Refresh() {
return
}
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -5,28 +5,27 @@ import (
)
func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) {
if len(clocks) == 0 {
title := fmt.Sprintf("\n%s", " no timezone data available")
widget.Redraw(widget.CommonSettings().Title, title, true)
return
}
str := ""
for idx, clock := range clocks {
rowColor := widget.settings.colors.rows.odd
if len(clocks) == 0 {
str = fmt.Sprintf("\n%s", " no timezone data available")
} else {
if idx%2 == 0 {
rowColor = widget.settings.colors.rows.even
for idx, clock := range clocks {
rowColor := widget.settings.colors.rows.odd
if idx%2 == 0 {
rowColor = widget.settings.colors.rows.even
}
str += fmt.Sprintf(
" [%s]%-12s %-10s %7s[white]\n",
rowColor,
clock.Label,
clock.Time(timeFormat),
clock.Date(dateFormat),
)
}
str += fmt.Sprintf(
" [%s]%-12s %-10s %7s[white]\n",
rowColor,
clock.Label,
clock.Time(timeFormat),
clock.Date(dateFormat),
)
}
widget.Redraw(widget.CommonSettings().Title, str, false)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, str, true })
}

View File

@ -47,7 +47,7 @@ func (widget *Widget) content() (string, string, bool) {
// Refresh executes the command and updates the view with the results
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
// String returns the string representation of the widget

View File

@ -8,7 +8,7 @@ import (
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -33,7 +33,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -46,7 +46,7 @@ func (widget *Widget) Refresh() {
widget.toplistWidget.Refresh(&wg)
wg.Wait()
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -42,7 +42,7 @@ func (widget *Widget) Refresh() {
if monitorErr != nil {
widget.monitors = nil
widget.SetItemCount(0)
widget.Redraw(widget.CommonSettings().Title, monitorErr.Error(), true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, monitorErr.Error(), true })
return
}
triggeredMonitors := []datadog.Monitor{}
@ -60,7 +60,7 @@ func (widget *Widget) Refresh() {
}
func (widget *Widget) Render() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) HelpText() string {

View File

@ -29,6 +29,7 @@ type Widget struct {
stories []*FeedItem
parser *gofeed.Parser
settings *Settings
err error
}
// NewWidget creates a new instance of a widget
@ -76,22 +77,21 @@ func (widget *Widget) Fetch(feedURLs []string) ([]*FeedItem, error) {
func (widget *Widget) Refresh() {
feedItems, err := widget.Fetch(widget.settings.feeds)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.err = err
widget.stories = nil
widget.SetItemCount(0)
} else {
widget.err = nil
widget.stories = feedItems
widget.SetItemCount(len(feedItems))
}
widget.stories = feedItems
widget.SetItemCount(len(feedItems))
widget.Render()
}
// Render sets up the widget data for redrawing to the screen
func (widget *Widget) Render() {
if widget.stories == nil {
return
}
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
@ -123,8 +123,14 @@ func (widget *Widget) fetchForFeed(feedURL string) ([]*FeedItem, error) {
}
func (widget *Widget) content() (string, string, bool) {
data := widget.stories
title := widget.CommonSettings().Title
if widget.err != nil {
return title, widget.err.Error(), true
}
data := widget.stories
if data == nil || len(data) == 0 {
return title, "No data", false
}
var str string
for idx, feedItem := range data {

View File

@ -25,7 +25,7 @@ func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
}
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -5,7 +5,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -76,9 +76,7 @@ func (widget *Widget) Refresh() {
}
gerrit, err := glb.NewClient(gerritUrl, httpClient)
if err != nil {
widget.View.SetWrap(true)
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
return
}
widget.gerrit = gerrit

View File

@ -7,7 +7,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -7,7 +7,7 @@ import (
)
func (widget *Widget) display() {
widget.TextWidget.RedrawFunc(widget.content)
widget.TextWidget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -5,7 +5,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -44,19 +44,19 @@ func (widget *Widget) Refresh() {
room, err := GetRoom(widget.settings.roomURI, widget.settings.apiToken)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
return
}
if room == nil {
widget.Redraw(widget.CommonSettings().Title, "No room", true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, "No room", true })
return
}
messages, err := GetMessages(room.ID, widget.settings.numberOfMessages, widget.settings.apiToken)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
return
}
widget.messages = messages
@ -72,7 +72,7 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -25,5 +25,5 @@ func (widget *Widget) Refresh() {
websiteReports := widget.Fetch()
contentTable := widget.createTable(websiteReports)
widget.Redraw(widget.CommonSettings().Title, contentTable, false)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, contentTable, false })
}

View File

@ -13,6 +13,7 @@ type Widget struct {
view.TextWidget
settings *Settings
cells []*sheets.ValueRange
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
@ -29,23 +30,24 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
cells, _ := widget.Fetch()
widget.cells = cells
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(cells), false)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string {
if valueRanges == nil {
return "error 1"
func (widget *Widget) content() (string, string, bool) {
if widget.cells == nil {
return widget.CommonSettings().Title, "error 1", false
}
res := ""
cells := utils.ToStrs(widget.settings.cellNames)
for i := 0; i < len(valueRanges); i++ {
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0])
for i := 0; i < len(widget.cells); i++ {
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, widget.cells[i].Values[0][0])
}
return res
return widget.CommonSettings().Title, res, false
}

View File

@ -48,7 +48,7 @@ func (widget *Widget) Refresh() {
}
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
return
}
var stories []Story
@ -67,7 +67,7 @@ func (widget *Widget) Refresh() {
// Render sets up the widget data for redrawing to the screen
func (widget *Widget) Render() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -11,8 +11,9 @@ import (
type Widget struct {
view.TextWidget
accounts []string
settings *Settings
data []*Status
err error
}
// NewWidget creates a new instance of a widget
@ -48,29 +49,28 @@ func (widget *Widget) Fetch(accounts []string) ([]*Status, error) {
func (widget *Widget) Refresh() {
data, err := widget.Fetch(widget.settings.accounts)
title := widget.CommonSettings().Title
title = title + widget.sinceDateForTitle()
var wrap bool
var content string
if err != nil {
wrap = true
content = err.Error()
widget.err = err
widget.data = nil
} else {
wrap = false
content = widget.contentFrom(data)
widget.err = nil
widget.data = data
}
widget.Redraw(title, content, wrap)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(data []*Status) string {
func (widget *Widget) content() (string, string, bool) {
title := widget.CommonSettings().Title
if widget.err != nil {
return title, widget.err.Error(), true
}
title = title + widget.sinceDateForTitle()
str := ""
for _, stat := range data {
for _, stat := range widget.data {
color := widget.settings.colors.ok
if stat.HasBeenCompromised() {
color = widget.settings.colors.pwned
@ -79,7 +79,7 @@ func (widget *Widget) contentFrom(data []*Status) string {
str += fmt.Sprintf(" [%s]%s[white]\n", color, stat.Account)
}
return str
return title, str, false
}
func (widget *Widget) sinceDateForTitle() string {

View File

@ -52,7 +52,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.ipinfo()
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
}
//this method reads the config and calls ipinfo for ip information

View File

@ -44,7 +44,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.ipinfo()
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
}
//this method reads the config and calls ipinfo for ip information

View File

@ -13,6 +13,7 @@ type Widget struct {
settings *Settings
view *View
err error
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
@ -47,24 +48,27 @@ func (widget *Widget) Refresh() {
widget.view = view
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
widget.err = err
widget.SetItemCount(0)
} else {
widget.SetItemCount(len(widget.view.Jobs))
}
widget.SetItemCount(len(widget.view.Jobs))
widget.Render()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
if widget.view == nil {
if widget.err != nil {
return title, widget.err.Error(), true
}
if widget.view == nil || len(widget.view.Jobs) == 0 {
return title, "No content to display", false
}

View File

@ -14,6 +14,7 @@ type Widget struct {
result *SearchResult
settings *Settings
err error
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
@ -43,23 +44,18 @@ func (widget *Widget) Refresh() {
)
if err != nil {
widget.err = err
widget.result = nil
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
}
widget.err = nil
widget.result = searchResult
widget.SetItemCount(len(searchResult.Issues))
widget.Render()
}
func (widget *Widget) Render() {
if widget.result == nil {
return
}
str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
widget.Redraw(str, widget.contentFrom(widget.result), false)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
@ -72,10 +68,19 @@ func (widget *Widget) openItem() {
}
}
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
func (widget *Widget) content() (string, string, bool) {
if widget.err != nil {
return widget.CommonSettings().Title, widget.err.Error(), true
}
title := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
str := " [red]Assigned Issues[white]\n"
for idx, issue := range searchResult.Issues {
if widget.result == nil || len(widget.result.Issues) == 0 {
return title, "No results to display", false
}
for idx, issue := range widget.result.Issues {
row := fmt.Sprintf(
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
widget.RowColor(idx),
@ -90,7 +95,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
str += utils.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
}
return str
return title, str, false
}
func (widget *Widget) issueTypeColor(issue *Issue) string {

View File

@ -48,7 +48,7 @@ func (widget *Widget) Refresh() {
if utils.Includes(widget.objects, "nodes") {
nodeList, nodeError := client.getNodes()
if nodeError != nil {
widget.Redraw(title, "[red] Error getting node data [white]\n", true)
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting node data [white]\n", true })
return
}
content += "[red]Nodes[white]\n"
@ -61,7 +61,7 @@ func (widget *Widget) Refresh() {
if utils.Includes(widget.objects, "deployments") {
deploymentList, deploymentError := client.getDeployments(widget.namespaces)
if deploymentError != nil {
widget.Redraw(title, "[red] Error getting deployment data [white]\n", true)
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting deployment data [white]\n", true })
return
}
content += "[red]Deployments[white]\n"
@ -74,7 +74,7 @@ func (widget *Widget) Refresh() {
if utils.Includes(widget.objects, "pods") {
podList, podError := client.getPods(widget.namespaces)
if podError != nil {
widget.Redraw(title, "[red] Error getting pod data [white]\n", false)
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting pod data [white]\n", false })
return
}
content += "[red]Pods[white]\n"
@ -84,7 +84,7 @@ func (widget *Widget) Refresh() {
content += "\n"
}
widget.Redraw(title, content, false)
widget.Redraw(func() (string, string, bool) { return title, content, false })
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -34,18 +34,17 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
// Refresh updates the onscreen contents of the widget
func (widget *Widget) Refresh() {
if log.LogFileMissing() {
return
}
logLines := widget.tailFile()
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(logLines), false)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(logLines []string) string {
func (widget *Widget) content() (string, string, bool) {
if log.LogFileMissing() {
return widget.CommonSettings().Title, "File missing", false
}
logLines := widget.tailFile()
str := ""
for _, line := range logLines {
@ -61,7 +60,7 @@ func (widget *Widget) contentFrom(logLines []string) string {
}
}
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) tailFile() []string {

View File

@ -7,7 +7,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -45,7 +45,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
}
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.nbascore)
widget.Redraw(widget.nbascore)
}
func (widget *Widget) HelpText() string {

View File

@ -31,7 +31,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -28,7 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -59,7 +59,7 @@ func (widget *Widget) Refresh() {
content = widget.contentFrom(onCalls, incidents)
}
widget.Redraw(widget.CommonSettings().Title, content, wrap)
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, content, wrap })
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -38,5 +38,5 @@ func (widget *Widget) content() (string, string, bool) {
func (widget *Widget) Refresh() {
widget.Battery.Refresh()
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}

View File

@ -15,6 +15,7 @@ type Widget struct {
items *Result
settings *Settings
err error
}
// NewWidget creates a new instance of a widget
@ -49,11 +50,13 @@ func (widget *Widget) Refresh() {
)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
widget.err = err
widget.items = nil
widget.SetItemCount(0)
} else {
widget.items = &items.Results
widget.SetItemCount(len(widget.items.Items))
}
widget.items = &items.Results
widget.SetItemCount(len(widget.items.Items))
widget.Render()
}
@ -61,17 +64,16 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
if widget.items == nil {
return
}
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
if widget.err != nil {
return widget.CommonSettings().Title, widget.err.Error(), true
}
result := widget.items
if result == nil {
if result == nil || len(result.Items) == 0 {
return title, "No results", false
}
var str string

View File

@ -32,7 +32,7 @@ func (widget *Widget) Refresh() {
return
}
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -51,7 +51,7 @@ func (w *Widget) refreshSpotifyInfos() error {
}
func (w *Widget) Refresh() {
w.RedrawFunc(w.createOutput)
w.Redraw(w.createOutput)
}
func (widget *Widget) HelpText() string {

View File

@ -154,7 +154,7 @@ func (w *Widget) refreshSpotifyInfos() error {
// Refresh refreshes the current view of the widget
func (w *Widget) Refresh() {
w.RedrawFunc(w.createOutput)
w.Redraw(w.createOutput)
}
func (widget *Widget) HelpText() string {

View File

@ -28,7 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.animation)
widget.Redraw(widget.animation)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -51,7 +51,7 @@ func (widget *Widget) display() (string, string, bool) {
}
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.display)
widget.Redraw(widget.display)
}
func (widget *Widget) prettyDate() string {

View File

@ -71,7 +71,7 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -9,7 +9,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -32,5 +32,5 @@ func (widget *Widget) content() (string, string, bool) {
}
func (widget *Widget) display() {
widget.ScrollableWidget.RedrawFunc(widget.content)
widget.ScrollableWidget.Redraw(widget.content)
}

View File

@ -10,7 +10,14 @@ import (
)
func (widget *Widget) content() (string, string, bool) {
title := widget.CommonSettings().Title
if widget.err != nil {
return title, widget.err.Error(), true
}
data := widget.torrents
if data == nil || len(data) == 0 {
return title, "No data", false
}
str := ""
for idx, torrent := range data {
@ -28,11 +35,11 @@ func (widget *Widget) content() (string, string, bool) {
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
}
return widget.CommonSettings().Title, str, false
return title, str, false
}
func (widget *Widget) display() {
widget.ScrollableWidget.RedrawFunc(widget.content)
widget.ScrollableWidget.Redraw(widget.content)
}
func (widget *Widget) prettyTorrentName(name string) string {

View File

@ -16,6 +16,7 @@ type Widget struct {
client *transmissionrpc.Client
settings *Settings
torrents []*transmissionrpc.Torrent
err error
}
// NewWidget creates a new instance of a widget
@ -63,14 +64,15 @@ func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
func (widget *Widget) Refresh() {
torrents, err := widget.Fetch()
if err != nil {
widget.err = err
widget.torrents = nil
widget.SetItemCount(0)
widget.ScrollableWidget.Redraw(widget.CommonSettings().Title, err.Error(), false)
return
} else {
widget.err = nil
widget.torrents = torrents
widget.SetItemCount(len(torrents))
}
widget.torrents = torrents
widget.SetItemCount(len(torrents))
widget.display()
}

View File

@ -15,6 +15,7 @@ type Widget struct {
builds *Builds
settings *Settings
err error
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
@ -44,41 +45,44 @@ func (widget *Widget) Refresh() {
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
widget.err = err
widget.builds = nil
widget.SetItemCount(0)
} else {
widget.err = nil
widget.builds = builds
widget.SetItemCount(len(builds.Builds))
}
widget.builds = builds
widget.SetItemCount(len(builds.Builds))
widget.Render()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
if widget.builds == nil {
return
}
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
var str string
for idx, build := range widget.builds.Builds {
if widget.err != nil {
str = widget.err.Error()
} else {
for idx, build := range widget.builds.Builds {
row := fmt.Sprintf(
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
widget.RowColor(idx),
buildColor(&build),
build.Repository.Name,
build.Number,
build.Branch.Name,
widget.RowColor(idx),
strings.Split(build.Commit.Message, "\n")[0],
build.CreatedBy.Login,
)
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
row := fmt.Sprintf(
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
widget.RowColor(idx),
buildColor(&build),
build.Repository.Name,
build.Number,
build.Branch.Name,
widget.RowColor(idx),
strings.Split(build.Commit.Message, "\n")[0],
build.CreatedBy.Login,
)
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
}
}
return title, str, false

View File

@ -27,7 +27,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -62,7 +62,7 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -27,5 +27,5 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings().Module.Type)
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
}

View File

@ -13,6 +13,7 @@ type Widget struct {
teams []OnCallTeam
settings *Settings
err error
}
// NewWidget creates a new widget
@ -36,18 +37,25 @@ func (widget *Widget) Refresh() {
teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
widget.err = err
widget.teams = nil
} else {
widget.err = nil
widget.teams = teams
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(widget.teams), true)
}
widget.Redraw(widget.content)
}
func (widget *Widget) contentFrom(teams []OnCallTeam) string {
func (widget *Widget) content() (string, string, bool) {
title := widget.CommonSettings().Title
if widget.err != nil {
return title, widget.err.Error(), true
}
teams := widget.teams
var str string
if teams == nil || len(teams) == 0 {
return "No teams specified"
return title, "No teams specified", false
}
for _, team := range teams {
@ -69,5 +77,5 @@ func (widget *Widget) contentFrom(teams []OnCallTeam) string {
if len(str) == 0 {
str = "Could not find any teams to display"
}
return str
return title, str, false
}

View File

@ -30,7 +30,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.prettyWeather()
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
}
//this method reads the config and calls wttr.in for pretty weather

View File

@ -9,7 +9,7 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -53,7 +53,7 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
widget.RedrawFunc(widget.content)
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {

View File

@ -72,8 +72,8 @@ func (widget *ScrollableWidget) Unselect() {
}
}
func (widget *ScrollableWidget) Redraw(title, content string, wrap bool) {
widget.TextWidget.Redraw(title, content, wrap)
func (widget *ScrollableWidget) Redraw(data func() (string, string, bool)) {
widget.TextWidget.Redraw(data)
widget.app.QueueUpdateDraw(func() {
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
})

View File

@ -29,16 +29,7 @@ func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}
func (widget *TextWidget) Redraw(title, text string, wrap bool) {
widget.app.QueueUpdateDraw(func() {
widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(text)
})
}
func (widget *TextWidget) RedrawFunc(data func() (string, string, bool)) {
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
widget.app.QueueUpdateDraw(func() {
title, content, wrap := data()
widget.View.Clear()