Add shared live run graphs, debugging, editor choice and draft cleanup
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// Each visit is a separate node, preserving cycles. Only recorded routes are drawn.
|
||||
func (m Model) runPathGraph() protocol.Graph {
|
||||
r := m.runDetail
|
||||
if r == nil {
|
||||
return protocol.Graph{}
|
||||
}
|
||||
graph := protocol.Graph{}
|
||||
for i, step := range r.Steps {
|
||||
node := protocol.Stage{Key: m.runVisitKey(i), Edges: map[string]string{}}
|
||||
if step.Target != "" && step.Outcome != "" {
|
||||
if protocol.IsTerminal(step.Target) {
|
||||
node.Edges[step.Outcome] = step.Target
|
||||
} else if i+1 < len(r.Steps) && r.Steps[i+1].Stage == step.Target {
|
||||
node.Edges[step.Outcome] = m.runVisitKey(i + 1)
|
||||
}
|
||||
}
|
||||
graph.Stages = append(graph.Stages, node)
|
||||
}
|
||||
return graph
|
||||
}
|
||||
|
||||
func (m Model) runVisitKey(index int) string {
|
||||
step := m.runDetail.Steps[index]
|
||||
return fmt.Sprintf("%d. %s (%s)", step.Sequence, step.Stage, m.stepProgressStatus(step))
|
||||
}
|
||||
|
||||
func (m Model) runGraphLines(_ int) []string {
|
||||
graph := m.runPathGraph()
|
||||
if len(graph.Stages) == 0 {
|
||||
return []string{"Waiting for the first stage…"}
|
||||
}
|
||||
selected := graph.Stages[len(graph.Stages)-1].Key
|
||||
if m.runStepIndex > 0 && m.runStepIndex <= len(graph.Stages) {
|
||||
selected = graph.Stages[m.runStepIndex-1].Key
|
||||
}
|
||||
return renderGraph(graph, selected)
|
||||
}
|
||||
|
||||
func (m Model) runsView(height int) string {
|
||||
if m.runDetail == nil || height < 14 {
|
||||
return m.runsDetailsView(height)
|
||||
}
|
||||
graphHeight := height / 2
|
||||
top, pan := m.runGraphTop, m.runGraphPan
|
||||
if !m.runGraphFocus {
|
||||
top, pan = m.runGraphFollow()
|
||||
}
|
||||
graph := graphViewport("Run path · actual visits", m.runGraphLines(max(3, m.width-4)), m.width, graphHeight, top, pan, m.runGraphFocus, "g graph/details · arrows pan · j/k scroll · live")
|
||||
details := m.runsDetailsView(height - graphHeight)
|
||||
return fitBlock(strings.Split(graph+"\n"+details, "\n"), m.width, height)
|
||||
}
|
||||
|
||||
func (m Model) runGraphFollow() (int, int) {
|
||||
graph := m.runPathGraph()
|
||||
if len(graph.Stages) == 0 {
|
||||
return 0, 0
|
||||
}
|
||||
index := len(graph.Stages) - 1
|
||||
if m.runStepIndex > 0 {
|
||||
index = min(m.runStepIndex-1, index)
|
||||
}
|
||||
layout := layoutGraph(graph)
|
||||
for _, node := range layout.nodes {
|
||||
if node.key == graph.Stages[index].Key {
|
||||
return node.y, max(0, node.x-(m.width-4-node.width)/2)
|
||||
}
|
||||
}
|
||||
return 0, 0
|
||||
}
|
||||
Reference in New Issue
Block a user