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

Merge pull request #538 from Seanstoppable/fixhighlightrace

Fix a bunch of race conditions
This commit is contained in:
Chris Cummer 2019-08-27 09:19:57 -07:00 committed by GitHub
commit 67658e172c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 325 additions and 288 deletions

View File

@ -16,6 +16,7 @@ type Widget struct {
view.TextWidget
settings *Settings
items []Item
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
@ -37,28 +38,28 @@ func (widget *Widget) Refresh() {
widget.settings.subdomain,
)
todayItems := client.Away(
widget.items = client.Away(
"timeOff",
time.Now().Local().Format(wtf.DateFormat),
time.Now().Local().Format(wtf.DateFormat),
)
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(todayItems), false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(items []Item) string {
if len(items) == 0 {
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
}
func (widget *Widget) content() (string, string, bool) {
str := ""
for _, item := range items {
if len(widget.items) == 0 {
str = fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
} else {
for _, item := range widget.items {
str += widget.format(item)
}
}
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) format(item Item) string {

View File

@ -32,28 +32,24 @@ func (widget *Widget) Refresh() {
return
}
builds, err := widget.Client.BuildsFor()
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
var content string
wrap := false
if err != nil {
wrap = true
content = err.Error()
} else {
content = widget.contentFrom(builds)
}
widget.Redraw(title, content, wrap)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(builds []*Build) string {
func (widget *Widget) content() (string, string, bool) {
builds, err := widget.Client.BuildsFor()
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
var str string
wrap := false
if err != nil {
wrap = true
str = err.Error()
} else {
for idx, build := range builds {
if idx > 10 {
return str
break
}
str += fmt.Sprintf(
@ -65,8 +61,9 @@ func (widget *Widget) contentFrom(builds []*Build) string {
build.AuthorName,
)
}
}
return str
return title, str, wrap
}
func buildColor(build *Build) string {

View File

@ -33,8 +33,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
return &widget
}
// Refresh executes the command and updates the view with the results
func (widget *Widget) Refresh() {
func (widget *Widget) content() (string, string, bool) {
result := widget.execute()
ansiTitle := tview.TranslateANSI(widget.CommonSettings().Title)
@ -43,7 +42,12 @@ func (widget *Widget) Refresh() {
}
ansiResult := tview.TranslateANSI(result)
widget.Redraw(ansiTitle, ansiResult, false)
return ansiTitle, ansiResult, false
}
// Refresh executes the command and updates the view with the results
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
}
// String returns the string representation of the widget

View File

@ -7,16 +7,15 @@ import (
)
func (widget *Widget) display() {
if ok == false {
widget.Redraw(widget.CommonSettings().Title, errorText, true)
return
}
summaryText := widget.summaryText(&widget.summaryList)
widget.Redraw(widget.CommonSettings().Title, summaryText, false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) summaryText(list *summaryList) string {
func (widget *Widget) content() (string, string, bool) {
if ok == false {
return widget.CommonSettings().Title, errorText, true
}
list := &widget.summaryList
str := ""
for _, baseCurrency := range list.items {
@ -62,7 +61,7 @@ func (widget *Widget) summaryText(list *summaryList) string {
}
return str
return widget.CommonSettings().Title, str, true
}

View File

@ -32,19 +32,18 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
positions, err := Fetch(widget.device_token)
if err != nil {
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
}
content := widget.contentFrom(positions)
widget.Redraw(widget.CommonSettings().Title, content, false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
func (widget *Widget) content() (string, string, bool) {
positions, err := Fetch(widget.device_token)
title := widget.CommonSettings().Title
if err != nil {
return title, err.Error(), true
}
res := ""
totalFiat := float32(0.0)
@ -86,7 +85,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
res += fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000)
}
return res
return title, res, true
}
//always the same

View File

@ -46,15 +46,15 @@ func (widget *Widget) Refresh() {
widget.toplistWidget.Refresh(&wg)
wg.Wait()
widget.display()
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
func (widget *Widget) content() (string, string, bool) {
str := ""
str += widget.priceWidget.Result
str += widget.toplistWidget.Result
widget.Redraw(widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false)
return widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false
}

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

@ -25,16 +25,14 @@ func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
}
func (widget *Widget) display() {
if widget.calEvents == nil || len(widget.calEvents) == 0 {
return
}
widget.TextWidget.Redraw(widget.settings.common.Title, widget.contentFrom(widget.calEvents), false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
func (widget *Widget) content() (string, string, bool) {
title := widget.settings.common.Title
calEvents := widget.calEvents
if (calEvents == nil) || (len(calEvents) == 0) {
return "No calendar events"
return title, "No calendar events", false
}
var str string
@ -76,7 +74,7 @@ func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
prevEvent = calEvent
}
return str
return title, str, false
}
func (widget *Widget) dayDivider(event, prevEvent *CalEvent) string {

View File

@ -5,11 +5,14 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
project := widget.currentGerritProject()
if project == nil {
widget.Redraw(widget.CommonSettings().Title, "Gerrit project data is unavailable", true)
return
return widget.CommonSettings().Title, "Gerrit project data is unavailable", true
}
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
@ -25,7 +28,7 @@ func (widget *Widget) display() {
str += " [red]My Outgoing Reviews[white]\n"
str += widget.displayMyOutgoingReviews(project, widget.settings.username)
widget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string {

View File

@ -7,10 +7,13 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
repoData := widget.currentData()
if repoData == nil {
widget.Redraw(widget.CommonSettings().Title, " Git repo data is unavailable ", false)
return
return widget.CommonSettings().Title, " Git repo data is unavailable ", false
}
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
@ -24,7 +27,7 @@ func (widget *Widget) display() {
str += "\n"
str += widget.formatCommits(repoData.Commits)
widget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) formatChanges(data []string) string {

View File

@ -7,11 +7,14 @@ import (
)
func (widget *Widget) display() {
widget.TextWidget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
repo := widget.currentGithubRepo()
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo))
if repo == nil {
widget.TextWidget.Redraw(title, " GitHub repo data is unavailable ", false)
return
return title, " GitHub repo data is unavailable ", false
}
_, _, width, _ := widget.View.GetRect()
@ -27,7 +30,7 @@ func (widget *Widget) display() {
str += widget.displayCustomQuery(repo, customQuery.filter, customQuery.perPage)
}
widget.TextWidget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {

View File

@ -5,11 +5,14 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
project := widget.currentGitlabProject()
if project == nil {
widget.Redraw(widget.CommonSettings().Title, " Gitlab project data is unavailable ", true)
return
return widget.CommonSettings().Title, " Gitlab project data is unavailable ", true
}
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
@ -24,7 +27,8 @@ func (widget *Widget) display() {
str += "\n"
str += " [red]My Merge Requests[white]\n"
str += widget.displayMyMergeRequests(project, widget.settings.username)
widget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string {

View File

@ -72,18 +72,16 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
if widget.messages == nil {
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)
if widget.messages == nil || len(widget.messages) == 0 {
return title, "No Messages To Display", false
}
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 +95,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

@ -67,17 +67,17 @@ func (widget *Widget) Refresh() {
// Render sets up the widget data for redrawing to the screen
func (widget *Widget) Render() {
if widget.stories == nil {
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
if stories == nil || len(stories) == 0 {
return title, "No stories to display", false
}
var str string
for idx, story := range stories {
@ -94,7 +94,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

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

View File

@ -2,7 +2,6 @@ package jenkins
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view"
@ -60,18 +59,18 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
if widget.view == nil {
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)
if widget.view == nil {
return title, "No content to display", false
}
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 +82,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

@ -7,10 +7,13 @@ import (
)
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
repoData := widget.currentData()
if repoData == nil {
widget.Redraw(widget.CommonSettings().Title, " Mercurial repo data is unavailable ", false)
return
return widget.CommonSettings().Title, " Mercurial repo data is unavailable ", false
}
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
@ -24,7 +27,7 @@ func (widget *Widget) display() {
str += "\n"
str += widget.formatCommits(repoData.Commits)
widget.Redraw(title, str, false)
return title, str, false
}
func (widget *Widget) formatChanges(data []string) string {

View File

@ -45,36 +45,37 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
}
func (widget *Widget) Refresh() {
widget.Redraw(widget.CommonSettings().Title, widget.nbascore(), false)
widget.RedrawFunc(widget.nbascore)
}
func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText()
}
func (widget *Widget) nbascore() string {
func (widget *Widget) nbascore() (string, string, bool) {
title := widget.CommonSettings().Title
cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days
curString := cur.Format("20060102") // Need 20060102 format to feed to api
client := &http.Client{}
req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil)
if err != nil {
return err.Error()
return title, err.Error(), true
}
req.Header.Set("Accept-Language", widget.language)
req.Header.Set("User-Agent", "curl")
response, err := client.Do(req)
if err != nil {
return err.Error()
return title, err.Error(), true
}
defer response.Body.Close()
if response.StatusCode != 200 {
return err.Error()
return title, err.Error(), true
} // Get data from data.nba.net and check if successful
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return err.Error()
return title, err.Error(), true
}
result := map[string]interface{}{}
json.Unmarshal(contents, &result)
@ -135,5 +136,5 @@ func (widget *Widget) nbascore() string {
}
allGame += fmt.Sprintf("%s%5s%v[white] %s %3s [white]vs %s%-3s %s\n", qColor, "Q", quarter, vTeam, vScore, hColor, hScore, hTeam) // Format the score and store in allgame
}
return allGame
return title, allGame, false
}

View File

@ -7,7 +7,6 @@ import (
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
nr "github.com/yfronto/newrelic"
)
type Widget struct {
@ -32,6 +31,12 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) content() (string, string, bool) {
app, appErr := widget.client.Application()
deploys, depErr := widget.client.Deployments()
@ -47,16 +52,7 @@ func (widget *Widget) Refresh() {
wrap = true
content = depErr.Error()
} else {
content = widget.contentFrom(deploys)
}
widget.Redraw(title, content, wrap)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
str := fmt.Sprintf(
content += fmt.Sprintf(
" %s\n",
"[red]Latest Deploys[white]",
)
@ -75,7 +71,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
revLen = len(deploy.Revision)
}
str += fmt.Sprintf(
content += fmt.Sprintf(
" [green]%s[%s] %s %-.16s[white]\n",
deploy.Revision[0:revLen],
lineColor,
@ -90,6 +86,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
}
}
}
}
return str
return title, content, wrap
}

View File

@ -28,10 +28,17 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
data, err := widget.Fetch(
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) content() (string, string, bool) {
onCallResponses, err := widget.Fetch(
widget.settings.scheduleIdentifierType,
widget.settings.schedule,
)
title := widget.CommonSettings().Title
var content string
wrap := false
@ -39,16 +46,6 @@ func (widget *Widget) Refresh() {
wrap = true
content = err.Error()
} else {
content = widget.contentFrom(data)
}
widget.Redraw(widget.CommonSettings().Title, content, wrap)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
str := ""
for _, data := range onCallResponses {
if (len(data.OnCallData.Recipients) == 0) && (widget.settings.displayEmpty == false) {
@ -62,11 +59,12 @@ func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
}
str += widget.cleanScheduleName(data.OnCallData.Parent.Name)
str += msg
content += widget.cleanScheduleName(data.OnCallData.Parent.Name)
content += msg
}
}
return str
return title, content, wrap
}
func (widget *Widget) cleanScheduleName(schedule string) string {

View File

@ -29,12 +29,14 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
return &widget
}
func (widget *Widget) Refresh() {
widget.Battery.Refresh()
func (widget *Widget) content() (string, string, bool) {
content := fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
content += "\n"
content += widget.Battery.String()
widget.Redraw(widget.CommonSettings().Title, content, true)
return widget.CommonSettings().Title, content, true
}
func (widget *Widget) Refresh() {
widget.Battery.Refresh()
widget.RedrawFunc(widget.content)
}

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

@ -32,15 +32,14 @@ func (widget *Widget) Refresh() {
return
}
data := NewSecurityData()
data.Fetch()
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(data), false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(data *SecurityData) string {
func (widget *Widget) content() (string, string, bool) {
data := NewSecurityData()
data.Fetch()
str := " [red]WiFi[white]\n"
str += fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
str += fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
@ -60,7 +59,7 @@ func (widget *Widget) contentFrom(data *SecurityData) string {
str += fmt.Sprintf(" %12s\n", data.DnsAt(1))
str += "\n"
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) labelColor(label string) string {

View File

@ -51,28 +51,23 @@ func (w *Widget) refreshSpotifyInfos() error {
}
func (w *Widget) Refresh() {
w.render()
w.RedrawFunc(w.createOutput)
}
func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText()
}
func (w *Widget) render() {
err := w.refreshSpotifyInfos()
func (w *Widget) createOutput() (string, string, bool) {
var content string
err := w.refreshSpotifyInfos()
if err != nil {
content = err.Error()
} else {
content = w.createOutput()
content = utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
content += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width)
content += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width)
content += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width)
}
w.Redraw(w.CommonSettings().Title, content, true)
}
func (w *Widget) createOutput() string {
output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width)
output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width)
output += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width)
return output
return w.CommonSettings().Title, content, true
}

View File

@ -154,19 +154,19 @@ func (w *Widget) refreshSpotifyInfos() error {
// Refresh refreshes the current view of the widget
func (w *Widget) Refresh() {
err := w.refreshSpotifyInfos()
if err != nil {
w.Redraw(w.CommonSettings().Title, err.Error(), true)
} else {
w.Redraw(w.CommonSettings().Title, w.createOutput(), false)
}
w.RedrawFunc(w.createOutput)
}
func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText()
}
func (w *Widget) createOutput() string {
func (w *Widget) createOutput() (string, string, bool) {
err := w.refreshSpotifyInfos()
var output string
if err != nil {
output = err.Error()
} else {
output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width)
output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width)
@ -176,5 +176,6 @@ func (w *Widget) createOutput() string {
} else {
output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] off\n"), w.CommonSettings().Width)
}
return output
}
return w.CommonSettings().Title, output, true
}

View File

@ -28,12 +28,12 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.Redraw(widget.CommonSettings().Title, widget.animation(), false)
widget.RedrawFunc(widget.animation)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) animation() string {
func (widget *Widget) animation() (string, string, bool) {
icons := []string{"|", "/", "-", "\\", "|"}
next := icons[widget.CurrentIcon]
@ -42,5 +42,5 @@ func (widget *Widget) animation() string {
widget.CurrentIcon = 0
}
return next
return widget.CommonSettings().Title, next, false
}

View File

@ -34,7 +34,7 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
return &widget
}
func (widget *Widget) Refresh() {
func (widget *Widget) display() (string, string, bool) {
content := fmt.Sprintf(
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
"Built",
@ -46,7 +46,12 @@ func (widget *Widget) Refresh() {
"Build",
widget.systemInfo.BuildVersion,
)
widget.Redraw(widget.CommonSettings().Title, content, false)
return widget.CommonSettings().Title, content, false
}
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.display)
}
func (widget *Widget) prettyDate() string {

View File

@ -71,6 +71,10 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
_, _, width, _ := widget.View.GetRect()
@ -82,7 +86,7 @@ func (widget *Widget) display() {
text += widget.plainText()
}
widget.Redraw(title, text, widget.settings.wrapText)
return title, text, widget.settings.wrapText
}
func (widget *Widget) fileName() 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

@ -27,6 +27,13 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) content() (string, string, bool) {
client := trello.NewClient(
widget.settings.apiKey,
widget.settings.accessToken,
@ -41,7 +48,7 @@ func (widget *Widget) Refresh() {
)
var title string
var content string
content := ""
wrap := false
if err != nil {
@ -49,31 +56,20 @@ func (widget *Widget) Refresh() {
title = widget.CommonSettings().Title
content = err.Error()
} else {
widget.View.SetWrap(false)
title = fmt.Sprintf(
"[white]%s: [green]%s ",
widget.CommonSettings().Title,
widget.settings.board,
)
content = widget.contentFrom(searchResult)
}
widget.Redraw(title, content, wrap)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
str := ""
for list, cardArray := range searchResult.TrelloCards {
str += fmt.Sprintf(" [red]%s[white]\n", list)
content += fmt.Sprintf(" [red]%s[white]\n", list)
for _, card := range cardArray {
str += fmt.Sprintf(" %s[white]\n", card.Name)
content += fmt.Sprintf(" %s[white]\n", card.Name)
}
content = fmt.Sprintf("%s\n", content)
}
str = fmt.Sprintf("%s\n", str)
}
return str
return title, content, wrap
}

View File

@ -62,6 +62,10 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
widget.RedrawFunc(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
widget.client.screenName = widget.CurrentSource()
tweets := widget.client.Tweets()
@ -69,8 +73,7 @@ func (widget *Widget) display() {
if len(tweets) == 0 {
str := fmt.Sprintf("\n\n\n%s", utils.CenterText("[lightblue]No Tweets[white]", 50))
widget.Redraw(title, str, true)
return
return title, str, true
}
_, _, width, _ := widget.View.GetRect()
@ -79,7 +82,7 @@ func (widget *Widget) display() {
str += widget.format(tweet)
}
widget.Redraw(title, str, true)
return title, str, true
}
// If the tweet's Username is the same as the account we're watching, no

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.Redraw(widget.CommonSettings().Title, content, true)
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
}

View File

@ -30,7 +30,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.prettyWeather()
widget.Redraw(widget.CommonSettings().Title, widget.result, false)
widget.RedrawFunc(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,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

@ -53,13 +53,14 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
widget.Redraw(title, widget.textContent(widget.result.Tickets), false)
widget.RedrawFunc(widget.content)
}
func (widget *Widget) textContent(items []Ticket) string {
func (widget *Widget) content() (string, string, bool) {
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
items := widget.result.Tickets
if len(items) == 0 {
return fmt.Sprintf("No unassigned tickets in queue - woop!!")
return title, "No unassigned tickets in queue - woop!!", false
}
str := ""
@ -67,7 +68,7 @@ func (widget *Widget) textContent(items []Ticket) string {
str += widget.format(data, idx)
}
return str
return title, str, false
}
func (widget *Widget) format(ticket Ticket, idx int) 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 {