mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Handle cases in which there is no weather data
This commit is contained in:
parent
6bf98c6a03
commit
f1a2f65bf1
@ -12,9 +12,13 @@ func (widget *Widget) display() {
|
||||
widget.View.Clear()
|
||||
|
||||
cityData := widget.currentData()
|
||||
if cityData == nil {
|
||||
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (1)")
|
||||
return
|
||||
}
|
||||
|
||||
if len(cityData.Weather) == 0 {
|
||||
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable.")
|
||||
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (2)")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,14 @@ func (widget *Widget) Prev() {
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) currentData() *owm.CurrentWeatherData {
|
||||
if len(widget.Data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if widget.Idx < 0 || widget.Idx >= len(widget.Data) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return widget.Data[widget.Idx]
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user