Restore box-and-arrow run diagrams without viewport list fallback

This commit is contained in:
2026-10-10 00:43:52 +01:00
parent f8ffde92f7
commit 977af96e23
3 changed files with 23 additions and 65 deletions
+2 -2
View File
@@ -196,8 +196,8 @@ the section containing the top visible row is highlighted and named in the pane
title. `Tab` cycles stages → details → graph (Shift+Tab reverses); `g` switches
graph focus. Each graph stage title shows live progress from its latest execution
visit, with pending stages dimmed. The graph is centered horizontally/vertically
when it fits; if the detailed diagram is too large, a compact branch overview
keeps all stage names, progress and declared routes. Oversized overviews remain
when it fits; the box-and-arrow diagram is retained at every viewport size,
never replaced with a stage list to fit. Oversized diagrams remain
pannable with `h/j/k/l` or arrows while the graph is focused; `c` recenters the
selected/current stage. `P` opens the
pinned pipeline (lowercase `p` remains an alias only on the runs list).
+1 -47
View File
@@ -5,7 +5,6 @@ import (
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)
@@ -126,15 +125,6 @@ func (m Model) runGraphFollow() (int, int) {
return 0, 0
}
rows := max(1, (m.height-4)/2-5)
lines, compact := m.fittedRunGraph(max(1, m.width-4), rows)
if compact {
for i, line := range lines {
if strings.HasPrefix(ansi.Strip(line), "▸ ") {
return max(0, i-rows/2), 0
}
}
return 0, 0
}
layout := layoutGraphAppearance(graph, appearance)
for _, node := range layout.nodes {
if node.key == selected {
@@ -144,42 +134,9 @@ func (m Model) runGraphFollow() (int, int) {
return 0, 0
}
func (m Model) fittedRunGraph(width, rows int) ([]string, bool) {
lines := m.runGraphLines(width)
widest := 0
for _, line := range lines {
widest = max(widest, ansi.StringWidth(line))
}
if widest <= width && len(lines) <= rows {
return lines, false
}
graph, selected, appearance := m.runGraphState()
if appearance == nil {
return lines, false
}
// Dense overview preserves every declared branch, rather than hiding nodes
// or scaling terminal text into unreadable glyphs.
lines = nil
for _, stage := range graph.Stages {
prefix := " "
if stage.Key == selected {
prefix = "▸ "
}
line := prefix + appearance.title(stage.Key, appearance.label(stage.Key), stage.Key == selected, graph)
for _, outcome := range outcomes(stage) {
target := protocol.ResolveTarget(outcome, stage.Edges[outcome])
color, bold := appearance.edgeStyle(graphEdge{source: stage.Key, outcome: outcome, target: target})
line += " " + lipgloss.NewStyle().Foreground(color).Bold(bold).Render(outcome+" → "+nodeLabel(target))
}
lines = append(lines, strings.Split(ansi.Wrap(line, max(1, width), ""), "\n")...)
}
lines = append(lines, appearance.title(protocol.SuccessEnd, "SUCCESS", false, graph)+" "+appearance.title(protocol.FailureEnd, "FAILURE", false, graph))
return lines, true
}
func (m Model) runGraphPanel(height, top, pan int) string {
width, rows := max(1, m.width-4), max(0, height-5)
lines, compact := m.fittedRunGraph(width, rows)
lines := m.runGraphLines(width)
widest := 0
for _, line := range lines {
widest = max(widest, ansi.StringWidth(line))
@@ -192,9 +149,6 @@ func (m Model) runGraphPanel(height, top, pan int) string {
body = append(body, strings.Repeat(" ", leftPad)+ansi.Cut(line, pan, pan+width-leftPad))
}
label := m.runGraphTitle()
if compact {
label += " · compact"
}
footer := "Tab pane · n/p stage · dim = not executed"
if widest > width || len(lines) > rows {
footer = "h/j/k/l pan · c center · Tab pane · n/p stage"
+20 -16
View File
@@ -33,7 +33,7 @@ func TestRunGraphStageTitlesShowLatestVisitProgress(t *testing.T) {
}
}
func TestRunGraphAutoFitsAndCentersCompactOverview(t *testing.T) {
func TestRunGraphRetainsDiagramInsteadOfListWhenOversized(t *testing.T) {
m := New(context.Background(), "")
m.width, m.height = 120, 40
m.runDetail = &protocol.RunDetail{Graph: protocol.Graph{Stages: []protocol.Stage{
@@ -44,27 +44,31 @@ func TestRunGraphAutoFitsAndCentersCompactOverview(t *testing.T) {
{Key: "add_one", Edges: map[string]string{"success": "report"}},
{Key: "report", Edges: map[string]string{"success": protocol.SuccessEnd}},
}}}
lines, compact := m.fittedRunGraph(116, 15)
if !compact || len(lines) > 15 {
t.Fatal("ordinary run graph did not fit", len(lines), compact)
}
for _, line := range lines {
if ansi.StringWidth(line) > 116 {
t.Fatal("compact graph exceeds available width")
}
}
view := ansi.Strip(m.runGraphPanel(20, 999, 999))
for _, want := range []string{"sum · ○ pending", "halve · ○ pending", "add_one · ○ pending", "odd → add_one", "even → halve", "SUCCESS", "FAILURE"} {
view := ansi.Strip(strings.Join(m.runGraphLines(116), "\n"))
for _, want := range []string{"sum · ○ pending", "halve · ○ pending", "add_one · ○ pending", "SUCCESS", "FAILURE", "╭", "╰", "▶", "│"} {
if !strings.Contains(view, want) {
t.Fatal("fitting hid stage or branch", want, view)
t.Fatal("graph lost diagram or stage", want, view)
}
}
if view != ansi.Strip(strings.Join(m.runGraphLines(30), "\n")) {
t.Fatal("small viewport replaced the diagram")
}
if !strings.Contains(ansi.Strip(m.runGraphPanel(20, 0, 0)), "h/j/k/l pan") {
t.Fatal("oversized diagram is not pannable")
}
}
func TestRunGraphCentersDiagramWhenItFits(t *testing.T) {
m := New(context.Background(), "")
m.width = 200
m.runDetail = &protocol.RunDetail{Graph: protocol.Graph{Stages: []protocol.Stage{{Key: "one", Edges: map[string]string{"success": protocol.SuccessEnd}}}}}
view := ansi.Strip(m.runGraphPanel(50, 999, 999))
if strings.Contains(view, "h/j/k/l pan") {
t.Fatal("fitted overview still requests scrolling")
t.Fatal("fitting graph still requires panning")
}
for _, line := range strings.Split(view, "\n") {
if strings.Contains(line, "sum ·") && strings.Index(line, "sum ·") < 10 {
t.Fatal("graph was not horizontally centered", line)
if strings.Contains(line, "one ·") && strings.Index(line, "one ·") < 30 {
t.Fatal("diagram not centered", line)
}
}
}