Soften TUI surfaces, typography and loading indicators
This commit is contained in:
@@ -132,6 +132,8 @@ On Home, **r** opens all recent runs; both Home panels show the shortcut.
|
||||
picker: **nvim** opens the draft Markdown file; **OpenCode** authors it with you.
|
||||
Canceling the picker creates no draft and publishes nothing.
|
||||
Wide terminals show runs and pipelines side by side; narrow terminals stack them.
|
||||
The TUI uses soft light/dark-adaptive cards, muted metadata, subtle selections,
|
||||
and local loading animations instead of heavy character borders and inverted bars.
|
||||
The dashboard includes all-history usage, success rate, average completed duration,
|
||||
per-pipeline usage, and a 14-day activity chart. CLI: `pipelines stats [--json]`.
|
||||
Use **:status** for a scrollable server/ntfy popup with health, ports, server-computer
|
||||
|
||||
@@ -110,3 +110,11 @@ cancel-without-creating, retained source/server/create-only metadata and templat
|
||||
source preservation. Compiled CLI/TUI PTY integration launches a new nvim draft
|
||||
(confirmation required), then a new mock OpenCode author that names and publishes
|
||||
through the real CLI (reloaded automatically, no extra submit prompt).
|
||||
|
||||
Soft-theme regression checks execute light/dark true-color rendering, ANSI-color
|
||||
fallback, borderless Home/popups, stage-color identity on tinted selections,
|
||||
continuous card backgrounds around nested colored labels, narrow-terminal
|
||||
dimensions, and local spinner animation across pending views without extra RPCs.
|
||||
Actual sample-data renders can be exported with `PIPELINES_TUI_PREVIEW_DIR=PATH
|
||||
go test -run TestSoftThemeRenderPreviews ./internal/tui` for Home, New and pipeline
|
||||
views in both themes. Compiled CLI/TUI PTY integration passed with the new styling.
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestPopupLayout(t *testing.T) {
|
||||
}
|
||||
var top int
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, "╭") {
|
||||
if strings.Contains(line, "Submit edited pipeline") {
|
||||
top = i
|
||||
if !strings.HasPrefix(line, " ") {
|
||||
t.Fatalf("dialog not horizontally centered: %q", line)
|
||||
|
||||
+15
-13
@@ -23,7 +23,7 @@ func (m Model) footerContent() string {
|
||||
if m.width < 60 {
|
||||
label = fmt.Sprintf(" ● %d NEW · :logs ", m.unread)
|
||||
}
|
||||
style = lipgloss.NewStyle().Foreground(themeAccent).Bold(true).Reverse(true)
|
||||
style = lipgloss.NewStyle().Foreground(themeAccent).Background(themeSelection)
|
||||
} else if len(m.lines) > 0 {
|
||||
style = lipgloss.NewStyle().Foreground(themeAccent).Bold(true)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func (m Model) footerContent() string {
|
||||
func (m Model) homeLines() []string {
|
||||
panelWidth := m.width
|
||||
if m.width >= 96 {
|
||||
panelWidth = (m.width - 1) / 2
|
||||
panelWidth = (m.width - 2) / 2
|
||||
}
|
||||
runs := []string{bar("Latest runs", fmt.Sprint(len(m.runs)), max(1, panelWidth-4), true),
|
||||
"r all runs · :status server & ntfy",
|
||||
@@ -51,24 +51,25 @@ func (m Model) homeLines() []string {
|
||||
runs = append(runs, "No runs yet.")
|
||||
}
|
||||
for _, r := range m.runs[:min(8, len(m.runs))] {
|
||||
runs = append(runs, fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Name, r.Version, m.progress(r.Status), runDuration(r.CreatedAt, r.FinishedAt)), " Started: "+dateLabel(r.CreatedAt))
|
||||
runs = append(runs, lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("#%d %s", r.ID, r.Name))+fmt.Sprintf(" · v%d · %s · %s", r.Version, m.progress(r.Status), runDuration(r.CreatedAt, r.FinishedAt)), lipgloss.NewStyle().Foreground(themeMuted).Render(" Started: "+dateLabel(r.CreatedAt)))
|
||||
if r.CurrentStage != "" && (r.Status == "running" || r.Status == "queued") {
|
||||
runs = append(runs, " Stage: "+r.CurrentStage)
|
||||
}
|
||||
runs = append(runs, "")
|
||||
}
|
||||
if len(m.runs) > 8 {
|
||||
runs = append(runs, "More runs: r or :runs (latest 50)")
|
||||
}
|
||||
lines := []string{bar("Existing pipelines", fmt.Sprintf("%d", len(m.pipelines)), max(1, panelWidth-4), true), "r all runs · / search · n new", ""}
|
||||
if !m.loaded {
|
||||
lines = append(lines, "Waiting for pipeline data…")
|
||||
lines = append(lines, m.loading("Waiting for pipeline data…"))
|
||||
} else if len(m.pipelines) == 0 {
|
||||
lines = append(lines, "No pipelines yet. Press b for templates, d for drafts, or n to create one.")
|
||||
} else {
|
||||
for _, p := range m.pipelines {
|
||||
lines = append(lines,
|
||||
fmt.Sprintf("%s v%d · %d stages", p.Name, p.Version, p.Stages),
|
||||
" Created: "+dateLabel(p.CreatedAt), " Updated: "+dateLabel(p.UpdatedAt))
|
||||
lipgloss.NewStyle().Bold(true).Render(p.Name)+lipgloss.NewStyle().Foreground(themeMuted).Render(fmt.Sprintf(" v%d · %d stages", p.Version, p.Stages)),
|
||||
lipgloss.NewStyle().Foreground(themeMuted).Render(" Created: "+dateLabel(p.CreatedAt)), lipgloss.NewStyle().Foreground(themeMuted).Render(" Updated: "+dateLabel(p.UpdatedAt)))
|
||||
if m.usage != nil {
|
||||
for _, u := range m.usage.Pipelines {
|
||||
if u.PipelineID == p.ID {
|
||||
@@ -77,6 +78,7 @@ func (m Model) homeLines() []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
lines = append(lines, "")
|
||||
}
|
||||
}
|
||||
if m.width < 8 {
|
||||
@@ -86,14 +88,14 @@ func (m Model) homeLines() []string {
|
||||
for i := range rows {
|
||||
rows[i] = ansi.Truncate(rows[i], max(1, width-4), "…")
|
||||
}
|
||||
content := lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(themeMuted).Padding(0, 1).Width(width - 2).
|
||||
Render(strings.Join(rows, "\n"))
|
||||
content := lipgloss.NewStyle().Background(themeSurface).Foreground(themeText).
|
||||
Padding(1, 2).Width(width).
|
||||
Render(surfaceContent(strings.Join(rows, "\n"), themeSurface))
|
||||
return content
|
||||
}
|
||||
panels := widget(runs, panelWidth) + "\n\n" + widget(lines, panelWidth)
|
||||
if m.width >= 96 {
|
||||
panels = lipgloss.JoinHorizontal(lipgloss.Top, widget(runs, panelWidth), " ", widget(lines, m.width-panelWidth-1))
|
||||
panels = lipgloss.JoinHorizontal(lipgloss.Top, widget(runs, panelWidth), " ", widget(lines, m.width-panelWidth-2))
|
||||
}
|
||||
return strings.Split(widget(m.usageLines(), m.width)+"\n"+panels, "\n")
|
||||
}
|
||||
@@ -296,9 +298,9 @@ func popup(width, height, preferredWidth int, lines []string) string {
|
||||
if len(lines) > 0 {
|
||||
lines[0] = bar(lines[0], "", inner, true)
|
||||
}
|
||||
dialog := lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(themeAccent).Padding(0, 1).Width(inner + 2).
|
||||
Render(strings.Join(lines, "\n"))
|
||||
dialog := lipgloss.NewStyle().Background(themeElevated).Foreground(themeText).
|
||||
Padding(1, 2).Width(inner + 4).
|
||||
Render(surfaceContent(strings.Join(lines, "\n"), themeElevated))
|
||||
if lipgloss.Width(dialog) > width || lipgloss.Height(dialog) > height {
|
||||
lines = lines[:min(len(lines), height)]
|
||||
for i := range lines {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/sahilm/fuzzy"
|
||||
)
|
||||
|
||||
@@ -69,7 +70,8 @@ func (m Model) updateEditorPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
func (m Model) editorPickerView(height int) string {
|
||||
input := m.editorInput
|
||||
input.Width = max(1, min(60, m.width-12))
|
||||
lines := []string{"Edit pipeline with…", input.View(), "Tab/Shift+Tab choose · type to search · Enter open · Esc cancel", ""}
|
||||
muted := lipgloss.NewStyle().Foreground(themeMuted)
|
||||
lines := []string{"Edit pipeline with…", input.View(), muted.Render("Tab/Shift+Tab choose · type to search · Enter open · Esc cancel"), ""}
|
||||
if m.editorDraft != nil && m.editorDraft.createOnly {
|
||||
lines[0] = "New pipeline with…"
|
||||
}
|
||||
@@ -77,9 +79,9 @@ func (m Model) editorPickerView(height int) string {
|
||||
for i, choice := range choices {
|
||||
lines = append(lines, menuOption(choice, i == m.editorIndex))
|
||||
if choice == "nvim" {
|
||||
lines = append(lines, " Write the pipeline Markdown in a retained draft file.")
|
||||
lines = append(lines, muted.Render(" Write the pipeline Markdown in a retained draft file."))
|
||||
} else {
|
||||
lines = append(lines, " Open the OpenCode harness to write it together.")
|
||||
lines = append(lines, muted.Render(" Open the OpenCode harness to write it together."))
|
||||
}
|
||||
}
|
||||
if len(choices) == 0 {
|
||||
|
||||
@@ -121,7 +121,8 @@ func TestStageAndDestinationHighlightsMatch(t *testing.T) {
|
||||
t.Fatal("outcome destination must match its rendered stage title")
|
||||
}
|
||||
m.stageIndex = 1
|
||||
if backgroundAt(t, strings.Join(m.graphLines(), "\n"), "reviewer") != destinationColor || foregroundAt(t, m.stageTabs(80), "reviewer") != destinationColor {
|
||||
selectionColor := backgroundAt(t, stageTitle("reviewer", "reviewer", true, m.detail.Graph), "reviewer")
|
||||
if selectionColor < 0 || backgroundAt(t, strings.Join(m.graphLines(), "\n"), "reviewer") != selectionColor || foregroundAt(t, strings.Join(m.graphLines(), "\n"), "reviewer") != destinationColor || foregroundAt(t, m.stageTabs(80), "reviewer") != destinationColor {
|
||||
t.Fatal("selection must preserve stage identity color")
|
||||
}
|
||||
for _, stage := range m.detail.Graph.Stages {
|
||||
@@ -129,8 +130,8 @@ func TestStageAndDestinationHighlightsMatch(t *testing.T) {
|
||||
t.Fatalf("stage %s is not highlighted", stage.Key)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(graph, "\x1b[") || backgroundAt(t, stageTitle("reviewer", "reviewer", true, m.detail.Graph), "reviewer") != destinationColor {
|
||||
t.Fatal("selected stage title should be visibly marked as a title bar")
|
||||
if !strings.Contains(graph, "\x1b[") || foregroundAt(t, stageTitle("reviewer", "reviewer", true, m.detail.Graph), "reviewer") != destinationColor {
|
||||
t.Fatal("selected stage should retain its identity on a soft highlight")
|
||||
}
|
||||
layout := layoutGraph(m.detail.Graph)
|
||||
rows := m.graphLines()
|
||||
@@ -140,7 +141,7 @@ func TestStageAndDestinationHighlightsMatch(t *testing.T) {
|
||||
}
|
||||
for x := node.x + 1; x < node.x+node.width-1; x++ {
|
||||
cell := ansi.Cut(rows[node.y+1], x, x+1)
|
||||
if backgroundAt(t, cell, ansi.Strip(cell)) != destinationColor {
|
||||
if backgroundAt(t, cell, ansi.Strip(cell)) != selectionColor {
|
||||
t.Fatalf("selected title padding at column %d is not filled", x)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-10
@@ -184,7 +184,7 @@ func New(ctx context.Context, url string) Model {
|
||||
ctx: ctx, url: url, status: "Connecting…", width: 80, height: 24,
|
||||
help: newHelp(),
|
||||
runPrompt: textarea.New(),
|
||||
runSpinner: spinner.New(spinner.WithSpinner(spinner.Dot), spinner.WithStyle(lipgloss.NewStyle().Foreground(themeAccent))),
|
||||
runSpinner: spinner.New(spinner.WithSpinner(spinner.Spinner{Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, FPS: time.Second / 12}), spinner.WithStyle(lipgloss.NewStyle().Foreground(themeAccent))),
|
||||
keys: keyMap{
|
||||
commands: key.NewBinding(key.WithKeys(":"), key.WithHelp(":", "commands")),
|
||||
search: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "search")),
|
||||
@@ -618,6 +618,9 @@ func (m *Model) appendLine(line string) {
|
||||
|
||||
func (m Model) View() string {
|
||||
connection := m.status
|
||||
if m.conn == nil {
|
||||
connection = m.loading(connection)
|
||||
}
|
||||
if len(m.notificationEndpoints) > 0 {
|
||||
endpoint := m.notificationEndpoints[0]
|
||||
address := endpoint.ServerURL
|
||||
@@ -658,14 +661,9 @@ func (m Model) View() string {
|
||||
}
|
||||
gap := max(0, m.width-lipgloss.Width(title)-lipgloss.Width(status))
|
||||
headerLine := lipgloss.NewStyle().Bold(true).Foreground(themeAccent).Render(title) + strings.Repeat(" ", gap) + lipgloss.NewStyle().Foreground(themeMuted).Render(status)
|
||||
header := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).
|
||||
BorderForeground(themeMuted).
|
||||
Width(m.width).Render(headerLine)
|
||||
footer := lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.NormalBorder()).BorderTop(true).
|
||||
BorderForeground(themeMuted).
|
||||
Width(m.width).Render(m.footerContent())
|
||||
header := lipgloss.NewStyle().Background(themeSurface).Foreground(themeText).
|
||||
Width(m.width).Render(surfaceContent(headerLine, themeSurface)) + "\n"
|
||||
footer := "\n" + lipgloss.NewStyle().Width(m.width).Render(m.footerContent())
|
||||
if m.height < 4 {
|
||||
return lipgloss.NewStyle().MaxHeight(m.height).Render(header + "\n" + footer)
|
||||
}
|
||||
@@ -715,7 +713,7 @@ func (m Model) View() string {
|
||||
content = m.statusView(bodyHeight)
|
||||
}
|
||||
if m.editorChecking {
|
||||
content = popup(m.width, bodyHeight, 76, []string{"Checking published edits", "Refreshing pipeline information…", "Local draft remains retained."})
|
||||
content = popup(m.width, bodyHeight, 76, []string{"Checking published edits", m.loading("Refreshing pipeline information…"), "Local draft remains retained."})
|
||||
}
|
||||
parts = append(parts, content)
|
||||
}
|
||||
|
||||
@@ -90,11 +90,11 @@ func TestLayoutResizes(t *testing.T) {
|
||||
if !strings.HasPrefix(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") || !strings.HasSuffix(lines[len(lines)-1], ":logs ") {
|
||||
t.Fatalf("invalid footer: %q", lines[len(lines)-1])
|
||||
}
|
||||
if !strings.Contains(lines[len(lines)-2], "─") {
|
||||
t.Fatal("missing footer separator")
|
||||
if strings.TrimSpace(lines[len(lines)-2]) != "" {
|
||||
t.Fatal("footer should have breathing room rather than a rule")
|
||||
}
|
||||
if !strings.Contains(lines[1], "─") || lipgloss.Width(lines[1]) != size.Width {
|
||||
t.Fatal("missing full-width header separator")
|
||||
if strings.TrimSpace(lines[1]) != "" {
|
||||
t.Fatal("header should have breathing room rather than a rule")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-14
@@ -60,23 +60,19 @@ func panel(width, height int, headers, body []string, footer string, focused boo
|
||||
lines = append(lines, visible...)
|
||||
}
|
||||
lines = append(lines, lipgloss.NewStyle().Foreground(themeMuted).Render(footer))
|
||||
color := themeMuted
|
||||
if focused {
|
||||
color = themeAccent
|
||||
}
|
||||
return lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).BorderForeground(color).
|
||||
Padding(0, 1).Width(width - 2).Render(fitBlock(lines, inner, height-2))
|
||||
return lipgloss.NewStyle().Background(themeSurface).Foreground(themeText).
|
||||
Padding(1, 2).Width(width).Render(surfaceContent(fitBlock(lines, inner, height-2), themeSurface))
|
||||
}
|
||||
|
||||
func bar(title, right string, width int, focused bool) string {
|
||||
left := ansi.Truncate(title, max(1, width), "…")
|
||||
if lipgloss.Width(left)+lipgloss.Width(right)+1 <= width {
|
||||
left += strings.Repeat(" ", width-lipgloss.Width(left)-lipgloss.Width(right)) + right
|
||||
left += strings.Repeat(" ", width-lipgloss.Width(left)-lipgloss.Width(right)) + lipgloss.NewStyle().Foreground(themeMuted).Bold(false).Render(right)
|
||||
}
|
||||
left += strings.Repeat(" ", max(0, width-lipgloss.Width(left)))
|
||||
s := lipgloss.NewStyle().Foreground(themeAccent).Bold(true)
|
||||
s := lipgloss.NewStyle().Foreground(themeText).Bold(true)
|
||||
if focused {
|
||||
s = s.Reverse(true)
|
||||
s = s.Foreground(themeAccent)
|
||||
}
|
||||
return s.Render(left)
|
||||
}
|
||||
@@ -101,7 +97,7 @@ func (m Model) pipelineToolbar() []string {
|
||||
if lipgloss.Width(buttons)+lipgloss.Width(state)+1 <= m.width {
|
||||
buttons += strings.Repeat(" ", m.width-lipgloss.Width(buttons)-lipgloss.Width(state)) + state
|
||||
}
|
||||
meta := lipgloss.NewStyle().Foreground(themeMuted).Render("Created ") + dateLabel(d.CreatedAt) + " │ " + lipgloss.NewStyle().Foreground(themeMuted).Render("Updated ") + dateLabel(d.UpdatedAt)
|
||||
meta := lipgloss.NewStyle().Foreground(themeMuted).Render("Created " + dateLabel(d.CreatedAt) + " · Updated " + dateLabel(d.UpdatedAt))
|
||||
if settings := d.Graph.Settings; settings != nil {
|
||||
var schedules []string
|
||||
for _, rule := range settings.Schedules {
|
||||
@@ -124,7 +120,7 @@ func (m Model) pipelineToolbar() []string {
|
||||
meta += " · historical, inactive"
|
||||
}
|
||||
}
|
||||
return []string{buttons, meta, lipgloss.NewStyle().Foreground(themeMuted).Render(strings.Repeat("─", m.width))}
|
||||
return []string{buttons, meta, ""}
|
||||
}
|
||||
|
||||
func (m Model) pipelineView(height int) string {
|
||||
@@ -133,7 +129,7 @@ func (m Model) pipelineView(height int) string {
|
||||
if m.requestedVersion > 0 {
|
||||
label = fmt.Sprintf("Loading version %d…", m.requestedVersion)
|
||||
}
|
||||
return fitBlock([]string{action(label, true)}, m.width, height)
|
||||
return fitBlock([]string{m.loading(label)}, m.width, height)
|
||||
}
|
||||
if m.detailError != "" {
|
||||
return fitBlock([]string{lipgloss.NewStyle().Foreground(themeError).Render("Cannot load pipeline: " + m.detailError), "Esc returns home."}, m.width, height)
|
||||
@@ -207,7 +203,7 @@ func graphViewport(label string, lines []string, width, height, scrollTop, pan i
|
||||
if pan+inner < graphWidth {
|
||||
label += " →"
|
||||
}
|
||||
headers := []string{bar(label, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, focused), lipgloss.NewStyle().Foreground(themeMuted).Render(strings.Repeat("─", inner))}
|
||||
headers := []string{bar(label, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), end, len(lines)), inner, focused), ""}
|
||||
if graphWidth > inner {
|
||||
footer = "←/→ pan · " + footer
|
||||
}
|
||||
@@ -364,7 +360,7 @@ func (m Model) stageColumnsWithHeaders(width int) (string, []string, []string) {
|
||||
count = 1
|
||||
}
|
||||
columnWidth := max(1, (width-(count-1)*3)/count)
|
||||
separator := lipgloss.NewStyle().Foreground(themeMuted).Render(" │ ")
|
||||
separator := " "
|
||||
var header string
|
||||
var result []string
|
||||
var rowHeaders []string
|
||||
|
||||
@@ -452,7 +452,7 @@ func (m Model) runsDetailsView(height int) string {
|
||||
title = "Failed runs · Esc back"
|
||||
}
|
||||
if m.requestedRunID > 0 || m.runStartRequest != "" {
|
||||
return fitBlock([]string{"Loading run…", m.runError, "Esc returns to runs"}, m.width, height)
|
||||
return fitBlock([]string{m.loading("Loading run…"), m.runError, "Esc returns to runs"}, m.width, height)
|
||||
}
|
||||
rows := []string{}
|
||||
runs := m.visibleRuns()
|
||||
|
||||
@@ -6,6 +6,10 @@ import (
|
||||
)
|
||||
|
||||
// Animation is driven by a local timer, never by extra server requests.
|
||||
func (m Model) loading(label string) string {
|
||||
return m.runSpinner.View() + " " + lipgloss.NewStyle().Foreground(themeMuted).Render(label)
|
||||
}
|
||||
|
||||
func (m Model) progress(status string) string {
|
||||
marker := "○"
|
||||
color := themeMuted
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/muesli/termenv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSoftSurfacesAdaptAndKeepCharacterChromeMinimal(t *testing.T) {
|
||||
profile, dark := lipgloss.ColorProfile(), lipgloss.HasDarkBackground()
|
||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||
defer func() { lipgloss.SetColorProfile(profile); lipgloss.SetHasDarkBackground(dark) }()
|
||||
var views []string
|
||||
for _, dark := range []bool{true, false} {
|
||||
lipgloss.SetHasDarkBackground(dark)
|
||||
m := New(context.Background(), "ws://localhost/connect")
|
||||
m.width = 120
|
||||
m.height = 30
|
||||
m.loaded = true
|
||||
view := m.View()
|
||||
views = append(views, view)
|
||||
if !strings.Contains(view, "48;2;") {
|
||||
t.Fatal("soft surfaces missing")
|
||||
}
|
||||
for _, s := range []string{view, popup(120, 26, 76, []string{"New pipeline with…", "nvim", "OpenCode"})} {
|
||||
plain := ansi.Strip(s)
|
||||
if strings.ContainsAny(plain, "╭╮╰╯│─") {
|
||||
t.Fatal("heavy character chrome remains", plain)
|
||||
}
|
||||
}
|
||||
for _, s := range []string{bar("Title", "3", 40, true), menuOption("OpenCode", true), action("edit", true), stageTab("planner", "planner", true)} {
|
||||
if strings.Contains(s, "[7m") || strings.Contains(s, ";7m") {
|
||||
t.Fatal("neon reverse-video selection remains", s)
|
||||
}
|
||||
}
|
||||
for _, line := range strings.Split(ansi.Strip(view), "\n") {
|
||||
if lipgloss.Width(line) > 120 {
|
||||
t.Fatal("surfaces changed layout width")
|
||||
}
|
||||
}
|
||||
}
|
||||
if views[0] == views[1] {
|
||||
t.Fatal("light and dark surfaces are identical")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadingUsesLocalAnimationAcrossPendingViews(t *testing.T) {
|
||||
m := New(context.Background(), "")
|
||||
m.detailLoading = true
|
||||
before := m.loading("Loading pipeline…")
|
||||
updated, cmd := m.Update(m.runSpinner.Tick())
|
||||
m = updated.(Model)
|
||||
if cmd == nil || before == m.loading("Loading pipeline…") || m.nextID != 0 || m.statusRequest != "" {
|
||||
t.Fatal("loading did not animate locally")
|
||||
}
|
||||
for _, view := range []string{m.pipelineView(20), m.templatesView(20), strings.Join(m.usageLines(), "\n")} {
|
||||
if !strings.Contains(view, m.runSpinner.View()) {
|
||||
t.Fatal("pending view lacks loading indicator", view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedLabelsDoNotPunchHolesInPanelBackground(t *testing.T) {
|
||||
profile := lipgloss.ColorProfile()
|
||||
lipgloss.SetColorProfile(termenv.ANSI)
|
||||
defer lipgloss.SetColorProfile(profile)
|
||||
nested := lipgloss.NewStyle().Bold(true).Foreground(themeAccent).Render("name") + " tail"
|
||||
view := panel(60, 8, []string{bar("Title", "1", 56, true)}, []string{nested}, "hint", true)
|
||||
want := backgroundAt(t, lipgloss.NewStyle().Background(themeSurface).Render("surface"), "surface")
|
||||
if want < 0 || backgroundAt(t, view, "tail") != want || backgroundAt(t, view, "hint") != want {
|
||||
t.Fatal("nested style resets leave holes in soft panel")
|
||||
}
|
||||
}
|
||||
|
||||
// Optional actual-render artifacts for visual review, without a live server.
|
||||
func TestSoftThemeRenderPreviews(t *testing.T) {
|
||||
dir := os.Getenv("PIPELINES_TUI_PREVIEW_DIR")
|
||||
if dir == "" {
|
||||
t.Skip("set PIPELINES_TUI_PREVIEW_DIR to export actual TUI renders")
|
||||
}
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile, dark := lipgloss.ColorProfile(), lipgloss.HasDarkBackground()
|
||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||
defer func() { lipgloss.SetColorProfile(profile); lipgloss.SetHasDarkBackground(dark) }()
|
||||
for _, theme := range []string{"dark", "light"} {
|
||||
lipgloss.SetHasDarkBackground(theme == "dark")
|
||||
m := New(context.Background(), "ws://localhost:8080/connect")
|
||||
m.width = 124
|
||||
m.height = 34
|
||||
m.loaded = true
|
||||
m.status = "localhost:8080"
|
||||
stamp := time.Now().UTC()
|
||||
m.pipelines = []protocol.PipelineSummary{{ID: 1, Name: "Repository maintenance", Version: 3, Stages: 4, CreatedAt: stamp.Add(-48 * time.Hour).Format(time.RFC3339), UpdatedAt: stamp.Format(time.RFC3339)}, {ID: 2, Name: "Release notes", Version: 1, Stages: 2, CreatedAt: stamp.Add(-24 * time.Hour).Format(time.RFC3339), UpdatedAt: stamp.Format(time.RFC3339)}}
|
||||
m.runs = []protocol.RunSummary{{ID: 18, Name: "Repository maintenance", Version: 3, Status: "running", CurrentStage: "reviewer", CreatedAt: stamp.Add(-47 * time.Second).Format(time.RFC3339)}, {ID: 17, Name: "Release notes", Version: 1, Status: "succeeded", CreatedAt: stamp.Add(-time.Hour).Format(time.RFC3339), FinishedAt: stamp.Add(-time.Hour + 82*time.Second).Format(time.RFC3339)}}
|
||||
m.usage = &protocol.UsageStats{RunCounts: protocol.RunCounts{Total: 18, Succeeded: 14, Failed: 2, Canceled: 1, Active: 1, AverageSeconds: 82}}
|
||||
for i, n := range []int{0, 1, 0, 2, 1, 0, 0, 3, 0, 1, 2, 1, 2, 2} {
|
||||
m.usage.Days = append(m.usage.Days, protocol.DailyUsage{Date: stamp.AddDate(0, 0, i-13).Format("2006-01-02"), Runs: n})
|
||||
}
|
||||
views := map[string]string{"home": m.View()}
|
||||
m.editorOpen = true
|
||||
m.editorDraft = &editedMsg{createOnly: true}
|
||||
m.editorInput = newInput()
|
||||
views["new"] = m.View()
|
||||
p := panelModel(t)
|
||||
p.width = 124
|
||||
p.height = 34
|
||||
views["pipeline"] = p.View()
|
||||
for name, view := range views {
|
||||
if err := os.WriteFile(filepath.Join(dir, name+"-"+theme+".ansi"), []byte(view), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func usageChart(days []protocol.DailyUsage) string {
|
||||
func (m Model) usageLines() []string {
|
||||
lines := []string{"Usage · all history"}
|
||||
if m.usage == nil {
|
||||
return append(lines, "Waiting for usage statistics…", ":status server & ntfy · r all runs")
|
||||
return append(lines, m.loading("Waiting for usage statistics…"), ":status server & ntfy · r all runs")
|
||||
}
|
||||
c := m.usage.RunCounts
|
||||
lines = append(lines, fmt.Sprintf("%d pipelines · %d runs · %d active · %s · avg completed %s", len(m.pipelines), c.Total, c.Active, successLabel(c), averageLabel(c)), fmt.Sprintf("Outcomes: %d succeeded · %d failed · %d canceled · %d interrupted", c.Succeeded, c.Failed, c.Canceled, c.Interrupted))
|
||||
|
||||
@@ -54,7 +54,7 @@ func (m Model) statusLines() []string {
|
||||
}
|
||||
lines := []string{"Client connection: " + connection}
|
||||
if m.statusRequest != "" {
|
||||
lines = append(lines, "Checking server and ntfy…")
|
||||
lines = append(lines, m.loading("Checking server and ntfy…"))
|
||||
}
|
||||
if m.statusError != "" {
|
||||
lines = append(lines, m.statusError)
|
||||
|
||||
@@ -98,7 +98,7 @@ func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m Model) templatesView(height int) string {
|
||||
if len(m.templates) == 0 {
|
||||
return fitBlock([]string{"Templates", "Loading examples…", m.templateError, "Esc back"}, m.width, height)
|
||||
return fitBlock([]string{"Templates", m.loading("Loading examples…"), m.templateError, "Esc back"}, m.width, height)
|
||||
}
|
||||
t := m.templates[m.templateIndex]
|
||||
mode := "Rendered Markdown"
|
||||
|
||||
+32
-12
@@ -6,16 +6,36 @@ import (
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ANSI colors refer to the terminal's configured palette, not fixed RGB values.
|
||||
// Unset backgrounds/foregrounds retain terminal defaults for light/dark themes.
|
||||
// Nested ANSI styles reset their backgrounds when they end. Restore the card's
|
||||
// base style after those resets, so colored labels don't leave terminal-colored
|
||||
// holes in an otherwise continuous surface. Plain/no-color output is unchanged.
|
||||
func surfaceContent(text string, background lipgloss.TerminalColor) string {
|
||||
paint := lipgloss.NewStyle().Foreground(themeText).Background(background).Render(" ")
|
||||
open := paint[:strings.IndexByte(paint, ' ')]
|
||||
if open == "" {
|
||||
return text
|
||||
}
|
||||
for _, reset := range []string{"\x1b[0m", "\x1b[m"} {
|
||||
text = strings.ReplaceAll(text, reset, reset+open)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
// Semantic accents use the terminal palette. Surfaces adapt to light/dark
|
||||
// terminals and are automatically reduced on terminals with fewer colors.
|
||||
var (
|
||||
themeAccent = lipgloss.Color("6")
|
||||
themePrimary = lipgloss.Color("4")
|
||||
themeMuted = lipgloss.Color("8")
|
||||
themeSuccess = lipgloss.Color("2")
|
||||
themeError = lipgloss.Color("1")
|
||||
themeAccent = lipgloss.Color("6")
|
||||
themePrimary = lipgloss.Color("4")
|
||||
themeMuted = lipgloss.Color("8")
|
||||
themeSuccess = lipgloss.Color("2")
|
||||
themeError = lipgloss.Color("1")
|
||||
themeSurface = lipgloss.AdaptiveColor{Light: "#F3F4F7", Dark: "#1D2129"}
|
||||
themeElevated = lipgloss.AdaptiveColor{Light: "#EAEDF3", Dark: "#252B35"}
|
||||
themeSelection = lipgloss.AdaptiveColor{Light: "#DCE7F5", Dark: "#2B3A4C"}
|
||||
themeText = lipgloss.AdaptiveColor{Light: "#303744", Dark: "#D9DEE7"}
|
||||
)
|
||||
|
||||
// Names keep their colors when stages are reordered or another version is opened.
|
||||
@@ -100,7 +120,7 @@ func stageTitle(key, label string, selected bool, graphs ...protocol.Graph) stri
|
||||
color := stageColor(key, graphs...)
|
||||
s := lipgloss.NewStyle().Foreground(color).Bold(true)
|
||||
if selected {
|
||||
s = s.Foreground(lipgloss.Color("0")).Background(color)
|
||||
s = s.Background(themeSelection)
|
||||
}
|
||||
return s.Render(label)
|
||||
}
|
||||
@@ -108,7 +128,7 @@ func stageTitle(key, label string, selected bool, graphs ...protocol.Graph) stri
|
||||
func stageTab(key, label string, selected bool, graphs ...protocol.Graph) string {
|
||||
s := lipgloss.NewStyle().Foreground(stageColor(key, graphs...)).Bold(true)
|
||||
if selected {
|
||||
s = s.Reverse(true).Underline(true)
|
||||
s = s.Background(themeSelection).Underline(true)
|
||||
}
|
||||
return s.Render(label)
|
||||
}
|
||||
@@ -118,9 +138,9 @@ func outcomeLabel(outcome, label string) string {
|
||||
}
|
||||
|
||||
func action(label string, selected bool) string {
|
||||
s := lipgloss.NewStyle().Foreground(themeAccent).Bold(true)
|
||||
s := lipgloss.NewStyle().Foreground(themeMuted)
|
||||
if selected {
|
||||
s = s.Foreground(themePrimary).Reverse(true)
|
||||
s = s.Foreground(themeAccent).Background(themeSelection).Bold(true)
|
||||
}
|
||||
return s.Render(" " + label + " ")
|
||||
}
|
||||
@@ -128,7 +148,7 @@ func action(label string, selected bool) string {
|
||||
func menuOption(label string, selected bool) string {
|
||||
s := lipgloss.NewStyle()
|
||||
if selected {
|
||||
s = s.Foreground(themePrimary).Bold(true).Reverse(true)
|
||||
s = s.Foreground(themeAccent).Background(themeSelection).Bold(true)
|
||||
}
|
||||
return s.Render(label)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user