54 lines
1009 B
Go
54 lines
1009 B
Go
package widget
|
|
|
|
import (
|
|
"github.com/Khan/genqlient/graphql"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type pipelineWidgetScreenSwitch tea.Model
|
|
|
|
type pipelineWidget struct {
|
|
currentView tea.Model
|
|
width int
|
|
height int
|
|
}
|
|
|
|
func (m pipelineWidget) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (m pipelineWidget) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case tea.WindowSizeMsg:
|
|
m.width = msg.Width
|
|
m.height = msg.Height
|
|
case pipelineWidgetScreenSwitch:
|
|
m.currentView = msg
|
|
m.currentView, _ = m.currentView.Update(tea.WindowSizeMsg{
|
|
Width: m.width,
|
|
Height: m.height,
|
|
})
|
|
}
|
|
|
|
var cmd tea.Cmd
|
|
m.currentView, cmd = m.currentView.Update(msg)
|
|
|
|
return m, cmd
|
|
}
|
|
|
|
func (m pipelineWidget) View() string {
|
|
return m.currentView.View()
|
|
}
|
|
|
|
func CreatePipelineWidget(client graphql.Client) (tea.Model, error) {
|
|
|
|
view, err := createPipelineWidgetList(client)
|
|
if err != nil {
|
|
return pipelineWidget{}, err
|
|
}
|
|
|
|
return pipelineWidget{
|
|
currentView: view,
|
|
}, nil
|
|
}
|