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

@@ -12,7 +12,6 @@ import (
type Widget struct {
wtf.TextWidget
app *tview.Application
result string
settings *Settings
}
@@ -21,7 +20,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings,
}
@@ -31,9 +29,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() {
widget.prettyWeather()
widget.app.QueueUpdateDraw(func() {
widget.View.SetText(widget.result)
})
widget.Redraw(widget.CommonSettings.Title, widget.result, false)
}
//this method reads the config and calls wttr.in for pretty weather

View File

@@ -9,31 +9,34 @@ import (
)
func (widget *Widget) display() {
err := ""
if widget.apiKeyValid() == false {
widget.View.SetText(" Environment variable WTF_OWM_API_KEY is not set")
return
err += " Environment variable WTF_OWM_API_KEY is not set\n"
}
cityData := widget.currentData()
if cityData == nil {
widget.View.SetText(" Weather data is unavailable: no city data")
return
err += " Weather data is unavailable: no city data\n"
}
if len(cityData.Weather) == 0 {
widget.View.SetText(" Weather data is unavailable: no weather data")
return
err += " Weather data is unavailable: no weather data"
}
widget.View.SetTitle(widget.title(cityData))
title := widget.CommonSettings.Title
var content string
if err != "" {
content = err
} else {
title = widget.title(cityData)
_, _, width, _ := widget.View.GetRect()
content = widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n"
content = content + widget.description(cityData) + "\n\n"
content = content + widget.temperatures(cityData) + "\n"
content = content + widget.sunInfo(cityData)
}
_, _, width, _ := widget.View.GetRect()
content := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n"
content = content + widget.description(cityData) + "\n\n"
content = content + widget.temperatures(cityData) + "\n"
content = content + widget.sunInfo(cityData)
widget.View.SetText(content)
widget.Redraw(title, content, false)
}
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {

View File

@@ -27,7 +27,6 @@ type Widget struct {
Data []*owm.CurrentWeatherData
Idx int
app *tview.Application
settings *Settings
}
@@ -40,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Idx: 0,
app: app,
settings: settings,
}
@@ -77,9 +75,7 @@ func (widget *Widget) Refresh() {
widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs))
}
widget.app.QueueUpdateDraw(func() {
widget.display()
})
widget.display()
}
// Next displays data for the next city data in the list. If the current city is the last