diff --git a/docs/cli.md b/docs/cli.md index 848af5e0..2d8c8c6b 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -195,7 +195,10 @@ the focused stage/details pane has a highlighted title and pointer. In details, 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 +visit. New run pages open with the graph focused and using roughly three quarters +of the available height. Tab expands the focused pane and contracts the others; +the stage list also widens when focused, and shrinks to a sidebar for details. +Pending stages are dimmed. The graph is centered horizontally/vertically 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 diff --git a/internal/tui/model.go b/internal/tui/model.go index 58b3e6be..51b531fb 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -336,6 +336,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } else if msg.Type == protocol.Run || msg.Type == protocol.RunStarted { accepted := m.runOpen && msg.RunDetail != nil && ((msg.Type == protocol.Run && msg.RunDetail.ID == m.requestedRunID) || (msg.Type == protocol.RunStarted && msg.ID == m.runStartRequest)) if accepted { + if m.runDetail == nil { + m.runGraphFocus = true + m.runDetailFocus = false + m.runGraphTop, m.runGraphPan = 0, 0 + } if msg.Type == protocol.RunStarted { m.runStartRequest = "" } diff --git a/internal/tui/run_detail.go b/internal/tui/run_detail.go index 0064507a..176e189e 100644 --- a/internal/tui/run_detail.go +++ b/internal/tui/run_detail.go @@ -171,6 +171,9 @@ func (m Model) runSidebarWidth() int { if m.width < 64 { return 0 } + if !m.runDetailFocus && !m.runGraphFocus { + return min(m.width-28, max(22, m.width*3/5)) + } return min(30, max(22, m.width/4)) } func (m Model) runDetailWidth() int { @@ -185,7 +188,8 @@ func (m Model) runPageSize() int { extra = 11 } if m.runDetail != nil && m.height-4 >= 14 { - extra += (m.height - 4) / 2 + graphHeight, _ := m.runPaneHeights(m.height - 4) + extra += graphHeight } return max(1, m.height-extra) } diff --git a/internal/tui/run_graph.go b/internal/tui/run_graph.go index 4944b817..711a48fc 100644 --- a/internal/tui/run_graph.go +++ b/internal/tui/run_graph.go @@ -90,16 +90,28 @@ func (m Model) runsView(height int) string { if m.runDetail == nil || height < 14 { return m.runsDetailsView(height) } - graphHeight := height / 2 + graphHeight, detailHeight := m.runPaneHeights(height) top, pan := m.runGraphTop, m.runGraphPan if !m.runGraphFocus { top, pan = m.runGraphFollow() } graph := m.runGraphPanel(graphHeight, top, pan) - details := m.runsDetailsView(height - graphHeight) + details := m.runsDetailsView(detailHeight) return fitBlock(strings.Split(graph+"\n"+details, "\n"), m.width, height) } +func (m Model) runPaneHeights(height int) (int, int) { + if height < 14 { + return 0, height + } + graphHeight := height / 4 + if m.runGraphFocus { + graphHeight = height * 3 / 4 + } + graphHeight = max(6, min(height-8, graphHeight)) + return graphHeight, height - graphHeight +} + func (m Model) runGraphTitle() string { r := m.runDetail if r == nil { @@ -124,7 +136,8 @@ func (m Model) runGraphFollow() (int, int) { if len(graph.Stages) == 0 { return 0, 0 } - rows := max(1, (m.height-4)/2-5) + graphHeight, _ := m.runPaneHeights(max(0, m.height-4)) + rows := max(1, graphHeight-5) layout := layoutGraphAppearance(graph, appearance) for _, node := range layout.nodes { if node.key == selected { diff --git a/internal/tui/run_pane_size_test.go b/internal/tui/run_pane_size_test.go new file mode 100644 index 00000000..9a4200e4 --- /dev/null +++ b/internal/tui/run_pane_size_test.go @@ -0,0 +1,63 @@ +package tui + +import ( + "context" + "strings" + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" + "github.com/charmbracelet/x/ansi" +) + +func TestRunPanesExpandWithTabFocus(t *testing.T) { + m := New(context.Background(), "") + m.width, m.height = 120, 48 + m.runOpen, m.keys.runs = true, true + m.requestedRunID = 1 + run := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1}, Steps: []protocol.RunStep{{Stage: "one", Status: "completed"}}} + updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run})) + m = updated.(Model) + graph, details := m.runPaneHeights(44) + if !m.runGraphFocus || graph <= details || graph+details != 44 { + t.Fatal("new run did not prioritize graph", graph, details) + } + graphPage := m.runPageSize() + m = runKey(m, "tab") + graph, details = m.runPaneHeights(44) + stageWidth := m.runSidebarWidth() + if m.runGraphFocus || m.runDetailFocus || details <= graph || stageWidth <= m.width/2 || m.runPageSize() <= graphPage { + t.Fatal("stage focus did not expand", graph, details, stageWidth) + } + m = runKey(m, "tab") + if !m.runDetailFocus || m.runSidebarWidth() >= stageWidth || m.width-m.runSidebarWidth() <= m.width/2 { + t.Fatal("details focus did not expand detail pane") + } + updated, _ = m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run})) + m = updated.(Model) + if !m.runDetailFocus || m.runGraphFocus { + t.Fatal("polling reset chosen focus") + } + m = runKey(m, "tab") + graph, details = m.runPaneHeights(44) + if !m.runGraphFocus || graph <= details { + t.Fatal("graph did not expand again") + } + for _, height := range []int{14, 18, 24, 44, 80} { + for _, pane := range []int{0, 1, 2} { + m.runDetailFocus, m.runGraphFocus = pane == 1, pane == 2 + graph, details = m.runPaneHeights(height) + if graph+details != height || graph < 6 || details < 8 { + t.Fatal("pane sizes exceed available height", height, graph, details) + } + view := m.runsView(height) + if len(strings.Split(view, "\n")) > height { + t.Fatal("expanded pane exceeds height") + } + for _, line := range strings.Split(view, "\n") { + if ansi.StringWidth(line) > m.width { + t.Fatal("expanded pane exceeds width") + } + } + } + } +}