Add live stage progress and centered auto-fitting run graphs
This commit is contained in:
+50
-3
@@ -108,6 +108,53 @@ func renderGraph(graph protocol.Graph, selection ...string) []string {
|
||||
type graphAppearance struct {
|
||||
nodes map[string]bool
|
||||
routes map[graphRoute]bool
|
||||
labels map[string]string
|
||||
}
|
||||
|
||||
func (a *graphAppearance) label(key string) string {
|
||||
if a != nil && a.labels[key] != "" {
|
||||
return a.labels[key]
|
||||
}
|
||||
return nodeLabel(key)
|
||||
}
|
||||
|
||||
func layoutGraphAppearance(graph protocol.Graph, appearance *graphAppearance) graphLayout {
|
||||
if appearance == nil || len(appearance.labels) == 0 {
|
||||
return layoutGraph(graph)
|
||||
}
|
||||
display := protocol.Graph{}
|
||||
keys := map[string]string{}
|
||||
label := func(key string) string {
|
||||
if protocol.IsTerminal(key) {
|
||||
return key
|
||||
}
|
||||
return appearance.label(key)
|
||||
}
|
||||
for _, stage := range graph.Stages {
|
||||
copy := stage
|
||||
copy.Key = label(stage.Key)
|
||||
keys[copy.Key] = stage.Key
|
||||
copy.Edges = map[string]string{}
|
||||
for outcome, target := range stage.Edges {
|
||||
copy.Edges[outcome] = label(protocol.ResolveTarget(outcome, target))
|
||||
}
|
||||
display.Stages = append(display.Stages, copy)
|
||||
}
|
||||
layout := layoutGraph(display)
|
||||
for i, node := range layout.nodes {
|
||||
if key, ok := keys[node.key]; ok {
|
||||
layout.nodes[i].key = key
|
||||
}
|
||||
}
|
||||
for i, edge := range layout.edges {
|
||||
if key, ok := keys[edge.source]; ok {
|
||||
layout.edges[i].source = key
|
||||
}
|
||||
if key, ok := keys[edge.target]; ok {
|
||||
layout.edges[i].target = key
|
||||
}
|
||||
}
|
||||
return layout
|
||||
}
|
||||
|
||||
type graphRoute struct{ source, outcome, target string }
|
||||
@@ -145,7 +192,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
|
||||
var lines []string
|
||||
edges, index := graphEdges(graph), 0
|
||||
for _, stage := range graph.Stages {
|
||||
lines = append(lines, appearance.title(stage.Key, "["+stage.Key+"]", stage.Key == selected, graph))
|
||||
lines = append(lines, appearance.title(stage.Key, "["+appearance.label(stage.Key)+"]", stage.Key == selected, graph))
|
||||
for range outcomes(stage) {
|
||||
e := edges[index]
|
||||
index++
|
||||
@@ -156,7 +203,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
|
||||
}
|
||||
return append(lines, appearance.title(protocol.FailureEnd, "[FAILURE]", false, graph)+" "+appearance.title(protocol.SuccessEnd, "[SUCCESS]", false, graph))
|
||||
}
|
||||
layout := layoutGraph(graph)
|
||||
layout := layoutGraphAppearance(graph, appearance)
|
||||
type cell struct {
|
||||
glyph rune
|
||||
color lipgloss.Color
|
||||
@@ -303,7 +350,7 @@ func renderGraphAppearance(graph protocol.Graph, selected string, appearance *gr
|
||||
result[row] = b.String()
|
||||
}
|
||||
for _, node := range layout.nodes {
|
||||
label, row := nodeLabel(node.key), node.y+1
|
||||
label, row := appearance.label(node.key), node.y+1
|
||||
left := ansi.Cut(result[row], 0, node.x+1)
|
||||
title := " " + label + strings.Repeat(" ", node.width-3-ansi.StringWidth(label))
|
||||
right := ansi.Cut(result[row], node.x+node.width-1, layout.width)
|
||||
|
||||
Reference in New Issue
Block a user