mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-1031 Rename WtfApp.app to WtfApp.tviewApp Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 Add scaffolding for main to support multiple WtfApp instances Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 WIP Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove common functionality from KeyboardWidget and into Base Signed-off-by: Chris Cummer <chriscummer@me.com> * Augment with some descriptive comments Signed-off-by: Chris Cummer <chriscummer@me.com> * Add full support for multiple app instances via the AppManager. Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com> * Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer <chriscummer@me.com>
72 lines
1.7 KiB
Go
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(tviewApp *tview.Application, settings *Settings) *Widget {
|
|
widget := &Widget{
|
|
TextWidget: view.NewTextWidget(tviewApp, nil, 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.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.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.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
|
|
}
|