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>
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package azuredevops
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
azr "github.com/microsoft/azure-devops-go-api/azuredevops"
|
|
azrBuild "github.com/microsoft/azure-devops-go-api/azuredevops/build"
|
|
"github.com/pkg/errors"
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/view"
|
|
)
|
|
|
|
type Widget struct {
|
|
view.TextWidget
|
|
cli azrBuild.Client
|
|
settings *Settings
|
|
displayBuffer string
|
|
ctx context.Context
|
|
}
|
|
|
|
func NewWidget(tviewApp *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
TextWidget: view.NewTextWidget(tviewApp, pages, settings.Common),
|
|
settings: settings,
|
|
}
|
|
|
|
widget.View.SetScrollable(true)
|
|
connection := azr.NewPatConnection(settings.orgURL, settings.apiToken)
|
|
ctx := context.Background()
|
|
|
|
cli, err := azrBuild.NewClient(ctx, connection)
|
|
if err != nil {
|
|
widget.displayBuffer = errors.Wrap(err, "could not create client 2").Error()
|
|
} else {
|
|
widget.cli = cli
|
|
widget.ctx = ctx
|
|
}
|
|
|
|
widget.refreshDisplayBuffer()
|
|
|
|
return &widget
|
|
}
|
|
|
|
func (widget *Widget) Refresh() {
|
|
widget.refreshDisplayBuffer()
|
|
widget.Redraw(widget.display)
|
|
}
|
|
|
|
func (widget *Widget) display() (string, string, bool) {
|
|
return widget.CommonSettings().Title, widget.displayBuffer, true
|
|
}
|
|
|
|
func (widget *Widget) refreshDisplayBuffer() {
|
|
if widget.cli == nil {
|
|
return
|
|
}
|
|
|
|
widget.displayBuffer = ""
|
|
|
|
widget.displayBuffer += fmt.Sprintf("[%s::bul] build status - %s\n",
|
|
widget.settings.labelColor,
|
|
widget.settings.projectName)
|
|
|
|
widget.displayBuffer += widget.getBuildStats()
|
|
}
|