1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/spacex/widget.go
Chris Cummer f0ca3b8a58
Another actions test (#889)
* Another actions test

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Add BuildTest action

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove lint check for the time being (so many issues)

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix issues found by errcheck

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix errors found by staticcheck

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix issues found by goimports

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Comment out the  action for the time being

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix shadowed variables

Signed-off-by: Chris Cummer <chriscummer@me.com>

* go mod tidy

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove buildtest.yml

Signed-off-by: Chris Cummer <chriscummer@me.com>

* go mod tidy

Signed-off-by: Chris Cummer <chriscummer@me.com>
2020-05-09 12:51:08 -07:00

72 lines
1.7 KiB
Go

package spacex
import (
"fmt"
"time"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
)
type Widget struct {
view.TextWidget
settings *Settings
err error
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := &Widget{
TextWidget: view.NewTextWidget(app, settings.common),
settings: settings,
}
return widget
}
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
widget.Redraw(widget.content)
}
func (widget *Widget) Render() {
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
var title = "Next SpaceX 🚀"
if widget.CommonSettings().Title != "" {
title = widget.CommonSettings().Title
}
launch, err := NextLaunch()
var str string
if err != nil {
handleError(widget, err)
} else {
str = fmt.Sprintf("[%s]Mission[white]\n", widget.settings.common.Colors.Subheading)
str += fmt.Sprintf("%s: %s\n", "Name", launch.MissionName)
str += fmt.Sprintf("%s: %s\n", "Date", wtf.UnixTime(launch.LaunchDate).Format(time.RFC822))
str += fmt.Sprintf("%s: %s\n", "Site", launch.LaunchSite.Name)
str += "\n"
str += fmt.Sprintf("[%s]Links[white]\n", widget.settings.common.Colors.Subheading)
str += fmt.Sprintf("%s: %s\n", "YouTube", launch.Links.YouTubeLink)
str += fmt.Sprintf("%s: %s\n", "Reddit", launch.Links.RedditLink)
if widget.CommonSettings().Height >= 2 {
str += "\n"
str += fmt.Sprintf("[%s]Details[white]\n", widget.settings.common.Colors.Subheading)
str += fmt.Sprintf("%s: %s\n", "RocketName", launch.Rocket.Name)
str += fmt.Sprintf("%s: %s\n", "Details", launch.Details)
}
}
return title, str, true
}
func handleError(widget *Widget, err error) {
widget.err = err
}