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>
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package buildkite
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/view"
|
|
)
|
|
|
|
type Widget struct {
|
|
view.TextWidget
|
|
settings *Settings
|
|
|
|
builds []Build
|
|
err error
|
|
}
|
|
|
|
func NewWidget(tviewApp *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
TextWidget: view.NewTextWidget(tviewApp, pages, settings.Common),
|
|
settings: settings,
|
|
}
|
|
|
|
widget.initializeKeyboardControls()
|
|
widget.View.SetScrollable(true)
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
builds, err := widget.getBuilds()
|
|
|
|
if err != nil {
|
|
widget.err = err
|
|
widget.builds = nil
|
|
} else {
|
|
widget.builds = builds
|
|
widget.err = nil
|
|
}
|
|
|
|
// The last call should always be to the display function
|
|
widget.display()
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) display() {
|
|
widget.Redraw(widget.content)
|
|
}
|
|
|
|
func (widget *Widget) content() (string, string, bool) {
|
|
title := fmt.Sprintf("%s - [green]%s", widget.CommonSettings().Title, widget.settings.orgSlug)
|
|
|
|
if widget.err != nil {
|
|
return title, widget.err.Error(), true
|
|
}
|
|
|
|
displayData := NewPipelinesDisplayData(widget.builds)
|
|
|
|
return title, displayData.Content(), false
|
|
}
|