From 977af96e23ccc2d7a795897be638d0e8714c82e6 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 10 Oct 2026 00:43:52 +0100 Subject: [PATCH] Restore box-and-arrow run diagrams without viewport list fallback --- docs/cli.md | 4 +-- internal/tui/run_graph.go | 48 +----------------------------- internal/tui/run_graph_fit_test.go | 36 ++++++++++++---------- 3 files changed, 23 insertions(+), 65 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index b09e51c8..848af5e0 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -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). diff --git a/internal/tui/run_graph.go b/internal/tui/run_graph.go index 29b1b737..4944b817 100644 --- a/internal/tui/run_graph.go +++ b/internal/tui/run_graph.go @@ -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" diff --git a/internal/tui/run_graph_fit_test.go b/internal/tui/run_graph_fit_test.go index 19ad511f..196b2ed6 100644 --- a/internal/tui/run_graph_fit_test.go +++ b/internal/tui/run_graph_fit_test.go @@ -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) } } }