mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Better weather formatting
This commit is contained in:
parent
b424655785
commit
07059749d6
@ -1,22 +1,13 @@
|
|||||||
package weather
|
package weather
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
//"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"text/template"
|
//"text/template"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
const weatherTemplate = `
|
|
||||||
{{range .Weather}}{{.Description}}{{end}}
|
|
||||||
|
|
||||||
Current: {{.Main.Temp}}° C
|
|
||||||
|
|
||||||
High: {{.Main.TempMax}}° C
|
|
||||||
Low: {{.Main.TempMin}}° C
|
|
||||||
`
|
|
||||||
|
|
||||||
func Widget() tview.Primitive {
|
func Widget() tview.Primitive {
|
||||||
data := Fetch()
|
data := Fetch()
|
||||||
|
|
||||||
@ -25,13 +16,16 @@ func Widget() tview.Primitive {
|
|||||||
widget.SetDynamicColors(true)
|
widget.SetDynamicColors(true)
|
||||||
widget.SetTitle(fmt.Sprintf(" 🌤 Weather - %s ", data.Name))
|
widget.SetTitle(fmt.Sprintf(" 🌤 Weather - %s ", data.Name))
|
||||||
|
|
||||||
var tpl bytes.Buffer
|
str := fmt.Sprintf("\n")
|
||||||
tmpl, _ := template.New("weather").Parse(weatherTemplate)
|
for _, weather := range data.Weather {
|
||||||
if err := tmpl.Execute(&tpl, data); err != nil {
|
str = str + fmt.Sprintf("%16s\n\n", weather.Description)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(widget, " %s ", tpl.String())
|
str = str + fmt.Sprintf("%10s: %4.1f° C\n\n", "Current", data.Main.Temp)
|
||||||
|
str = str + fmt.Sprintf("%10s: %4.1f° C\n", "High", data.Main.TempMax)
|
||||||
|
str = str + fmt.Sprintf("%10s: %4.1f° C\n", "Low", data.Main.TempMin)
|
||||||
|
|
||||||
|
fmt.Fprintf(widget, " %s ", str)
|
||||||
|
|
||||||
return widget
|
return widget
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user