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

Convert the bulk of modules over to RedrawFunc

This commit is contained in:
Sean Smith 2019-08-26 23:07:02 -04:00
parent 51e4325f0b
commit 3a716bcf9a
25 changed files with 214 additions and 224 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 {
str += widget.format(item)
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,41 +32,38 @@ 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 {
var str string
for idx, build := range builds {
if idx > 10 {
return str
}
func (widget *Widget) content() (string, string, bool) {
builds, err := widget.Client.BuildsFor()
str += fmt.Sprintf(
"[%s] %s-%d (%s) [white]%s\n",
buildColor(build),
build.Reponame,
build.BuildNum,
build.Branch,
build.AuthorName,
)
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 {
break
}
str += fmt.Sprintf(
"[%s] %s-%d (%s) [white]%s\n",
buildColor(build),
build.Reponame,
build.BuildNum,
build.Branch,
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

@ -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

@ -72,15 +72,14 @@ func (widget *Widget) HelpText() string {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
if widget.messages == nil {
return
}
widget.RedrawFunc(widget.content)
}
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 widget.messages {
row := fmt.Sprintf(

View File

@ -67,10 +67,6 @@ func (widget *Widget) Refresh() {
// Render sets up the widget data for redrawing to the screen
func (widget *Widget) Render() {
if widget.stories == nil {
return
}
widget.RedrawFunc(widget.content)
}
@ -79,6 +75,9 @@ func (widget *Widget) Render() {
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 {

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

@ -59,15 +59,14 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) Render() {
if widget.view == nil {
return
}
widget.RedrawFunc(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 {
return title, "No content to display", false
}
var str string
jobs := widget.view.Jobs

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,49 +52,41 @@ func (widget *Widget) Refresh() {
wrap = true
content = depErr.Error()
} else {
content = widget.contentFrom(deploys)
}
content += fmt.Sprintf(
" %s\n",
"[red]Latest Deploys[white]",
)
widget.Redraw(title, content, wrap)
}
revisions := []string{}
/* -------------------- Unexported Functions -------------------- */
for _, deploy := range deploys {
if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) {
lineColor := "white"
if wtf.IsToday(deploy.Timestamp) {
lineColor = "lightblue"
}
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
str := fmt.Sprintf(
" %s\n",
"[red]Latest Deploys[white]",
)
revLen := 8
if revLen > len(deploy.Revision) {
revLen = len(deploy.Revision)
}
revisions := []string{}
content += fmt.Sprintf(
" [green]%s[%s] %s %-.16s[white]\n",
deploy.Revision[0:revLen],
lineColor,
deploy.Timestamp.Format("Jan 02 15:04 MST"),
utils.NameFromEmail(deploy.User),
)
for _, deploy := range deploys {
if (deploy.Revision != "") && utils.DoesNotInclude(revisions, deploy.Revision) {
lineColor := "white"
if wtf.IsToday(deploy.Timestamp) {
lineColor = "lightblue"
}
revisions = append(revisions, deploy.Revision)
revLen := 8
if revLen > len(deploy.Revision) {
revLen = len(deploy.Revision)
}
str += fmt.Sprintf(
" [green]%s[%s] %s %-.16s[white]\n",
deploy.Revision[0:revLen],
lineColor,
deploy.Timestamp.Format("Jan 02 15:04 MST"),
utils.NameFromEmail(deploy.User),
)
revisions = append(revisions, deploy.Revision)
if len(revisions) == widget.settings.deployCount {
break
if len(revisions) == widget.settings.deployCount {
break
}
}
}
}
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,34 +46,25 @@ func (widget *Widget) Refresh() {
wrap = true
content = err.Error()
} else {
content = widget.contentFrom(data)
for _, data := range onCallResponses {
if (len(data.OnCallData.Recipients) == 0) && (widget.settings.displayEmpty == false) {
continue
}
var msg string
if len(data.OnCallData.Recipients) == 0 {
msg = " [gray]no one[white]\n\n"
} else {
msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
}
content += widget.cleanScheduleName(data.OnCallData.Parent.Name)
content += msg
}
}
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) {
continue
}
var msg string
if len(data.OnCallData.Recipients) == 0 {
msg = " [gray]no one[white]\n\n"
} else {
msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
}
str += widget.cleanScheduleName(data.OnCallData.Parent.Name)
str += 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

@ -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,27 +154,28 @@ 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 {
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)
output += utils.CenterText(fmt.Sprintf("[green]Album:[white] %v\n", w.Info.Album), w.CommonSettings().Width)
if w.playerState.ShuffleState {
output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] on\n"), w.CommonSettings().Width)
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]Shuffle:[white] off\n"), w.CommonSettings().Width)
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)
output += utils.CenterText(fmt.Sprintf("[green]Album:[white] %v\n", w.Info.Album), w.CommonSettings().Width)
if w.playerState.ShuffleState {
output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] on\n"), w.CommonSettings().Width)
} 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

@ -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)
}
for list, cardArray := range searchResult.TrelloCards {
content += fmt.Sprintf(" [red]%s[white]\n", list)
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)
for _, card := range cardArray {
str += fmt.Sprintf(" %s[white]\n", card.Name)
for _, card := range cardArray {
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

@ -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

@ -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 {