package terminalui import ( "strings" "bloomfx.dev/bloom/flex" "github.com/charmbracelet/x/ansi" ) // GraphColumns reserves the left inset and separator before distributing the // remaining cells. Node positioning and the painter use the same geometry. func GraphColumns(width int) (graph, detail int) { if width < SideWidth { return max(1, width-1), 0 } var sizes [2]int flex.Split(sizes[:], width-1, 1, []flex.Track{flex.Fill(1), flex.Fixed(min(46, max(36, width/3)))}) return sizes[0], sizes[1] } type Graph struct { Canvas func(width, height int) []string Detail func(height int) []string Header, Divider, Rule string Summary, Actions []string } func (g Graph) Render(width, height int) string { if width < 1 || height < 1 { return "" } rows := make([]string, 0, height) rows = append(rows, " "+g.Header) graph, detail := GraphColumns(width) body := max(0, height-1-len(g.Actions)) summary := g.Summary[:min(len(g.Summary), max(0, body/2-1))] if len(summary) > 0 { body -= len(summary) + 1 } var pane []string if detail > 0 { pane = g.Detail(body) } for i, line := range g.Canvas(graph, body) { if detail > 0 { line += g.Divider + " " if i < len(pane) { line += ansi.Truncate(pane[i], detail-1, "…") } } rows = append(rows, " "+line) } if len(summary) > 0 { rows = append(rows, " "+g.Rule) for _, row := range summary { rows = append(rows, " "+ansi.Truncate(row, width-1, "…")) } } rows = append(rows, g.Actions...) if len(rows) > height { rows = rows[len(rows)-height:] } for i, row := range rows { rows[i] = ansi.Truncate(row, width, "…") } return strings.Join(rows, "\n") }