Add pipeline creation UI

This commit is contained in:
2023-02-24 18:30:39 -07:00
parent 5c1c1478ee
commit 0710306800
3 changed files with 100 additions and 47 deletions
+45 -2
View File
@@ -3,6 +3,7 @@ package widget
import (
"context"
"fmt"
"io"
"git.ohea.xyz/cursorius/tui/queries"
"github.com/Khan/genqlient/graphql"
@@ -27,14 +28,19 @@ func (m pipelineWidgetList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch msg.String() {
case "down":
if m.list.Index() < len(m.list.Items()) {
if m.list.Index() < len(m.list.Items())-1 {
m.list.Select(m.list.Index() + 1)
} else if m.list.Index() == len(m.list.Items())-1 {
m.list.Select(0)
}
case "up":
if m.list.Index() > 0 {
m.list.Select(m.list.Index() - 1)
} else if m.list.Index() == 0 {
m.list.Select(len(m.list.Items()) - 1)
}
case "enter":
case "e":
if m.list.Index() < len(m.list.Items())-1 {
//item := m.list.SelectedItem()
//if item, ok := item.(pipelineListItem); ok {
@@ -70,6 +76,43 @@ type pipelineListItem struct {
id string
}
type pipelineCreateListItem string
func (i pipelineListItem) FilterValue() string { return "" }
func (i pipelineCreateListItem) FilterValue() string { return "" }
type pipelineListItemDelegate struct{}
func (d pipelineListItemDelegate) Height() int { return 1 }
func (d pipelineListItemDelegate) Spacing() int { return 0 }
func (d pipelineListItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
func (d pipelineListItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
switch i := listItem.(type) {
case pipelineListItem:
fn := itemStyle.Render
faintFn := faintItemStyle.Render
if index == m.Index() {
fn = func(s string) string {
return selectedItemStyle.Render("> " + s)
}
faintFn = faintSelectedItemStyle.Render
}
str := fn(i.name) + faintFn(" ("+i.id+")")
fmt.Fprint(w, str)
case pipelineCreateListItem:
fn := itemStyle.Render
if index == m.Index() {
fn = func(s string) string {
return selectedItemStyle.Render("> " + s)
}
}
str := string(i)
fmt.Fprint(w, fn(str))
}
}
func createPipelineWidgetList(client graphql.Client) (tea.Model, error) {
getPipelineResp, err := queries.GetPipelines(context.Background(), client)
if err != nil {