Add shared live run graphs, debugging, editor choice and draft cleanup
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/sahilm/fuzzy"
|
||||
)
|
||||
|
||||
func (m Model) editorChoices() []string {
|
||||
choices := []string{"nvim", "OpenCode"}
|
||||
if query := strings.TrimSpace(m.editorInput.Value()); query != "" {
|
||||
var result []string
|
||||
for _, match := range fuzzy.Find(query, choices) {
|
||||
result = append(result, match.Str)
|
||||
}
|
||||
return result
|
||||
}
|
||||
return choices
|
||||
}
|
||||
|
||||
func (m Model) updateEditorPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
choices := m.editorChoices()
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
m.editorOpen = false
|
||||
m.editorDraft = nil
|
||||
return m, nil
|
||||
case "tab", "down", "ctrl+n":
|
||||
if len(choices) > 0 {
|
||||
m.editorIndex = (m.editorIndex + 1) % len(choices)
|
||||
}
|
||||
return m, nil
|
||||
case "shift+tab", "up", "ctrl+p":
|
||||
if len(choices) > 0 {
|
||||
m.editorIndex = (m.editorIndex + len(choices) - 1) % len(choices)
|
||||
}
|
||||
return m, nil
|
||||
case "enter":
|
||||
if len(choices) == 0 || m.editorDraft == nil {
|
||||
return m, nil
|
||||
}
|
||||
choice := strings.ToLower(choices[min(m.editorIndex, len(choices)-1)])
|
||||
d := m.editorDraft
|
||||
m.editorOpen = false
|
||||
m.editorDraft = nil
|
||||
return m, editDraftUsing(choice, d.name, d.source, true, false, draft.Draft{Server: m.url, BaseVersion: d.baseVersion})
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
m.editorInput, cmd = m.editorInput.Update(msg)
|
||||
m.editorIndex = 0
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m Model) editorPickerView(height int) string {
|
||||
input := m.editorInput
|
||||
input.Width = max(1, min(60, m.width-12))
|
||||
lines := []string{"Edit pipeline with…", input.View(), "Tab/Shift+Tab choose · type to search · Enter open · Esc cancel", ""}
|
||||
choices := m.editorChoices()
|
||||
for i, choice := range choices {
|
||||
lines = append(lines, menuOption(choice, i == m.editorIndex))
|
||||
}
|
||||
if len(choices) == 0 {
|
||||
lines = append(lines, "No matching editor.")
|
||||
}
|
||||
return popup(m.width, height, 80, lines)
|
||||
}
|
||||
Reference in New Issue
Block a user