Files
pipelines/internal/harness/style.go
T
alan 05ae530442 Make Pipelines Docker-only with OpenCode and Pi
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers.

Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent.

Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
2026-10-11 23:00:25 +01:00

128 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package harness
import (
"os"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"golang.org/x/term"
)
// Local style vocabulary mirrors internal/tui's soft theme without importing it
// (that would create an import cycle). Accents use the terminal palette; surfaces
// adapt to light/dark terminals and reduce automatically on low-color terminals.
var (
styleAccent = lipgloss.Color("6")
styleMuted = lipgloss.Color("8")
styleError = lipgloss.Color("1")
styleSelection = lipgloss.AdaptiveColor{Light: "#DCE7F5", Dark: "#2B3A4C"}
)
// plainOutput reports whether styled ANSI must be suppressed: NO_COLOR (any
// value, per no-color.org) or a dumb terminal.
func plainOutput() bool {
if _, set := os.LookupEnv("NO_COLOR"); set {
return true
}
return strings.EqualFold(os.Getenv("TERM"), "dumb")
}
// isTerminal reports whether a stream is a real TTY. A character device such as
// /dev/null is not a TTY and must never launch an interactive picker.
func isTerminal(stream any) bool {
file, ok := stream.(*os.File)
if !ok {
return false
}
return term.IsTerminal(int(file.Fd()))
}
// pickerStyles renders plain text unchanged when color is unavailable.
type pickerStyles struct{ plain bool }
func (s pickerStyles) title(text string) string {
if s.plain {
return text
}
return lipgloss.NewStyle().Foreground(styleAccent).Bold(true).Render(text)
}
func (s pickerStyles) step(text string) string {
if s.plain {
return text
}
return lipgloss.NewStyle().Foreground(styleAccent).Bold(true).Render(text)
}
func (s pickerStyles) muted(text string) string {
if s.plain {
return text
}
return lipgloss.NewStyle().Foreground(styleMuted).Render(text)
}
func (s pickerStyles) error(text string) string {
if s.plain {
return text
}
return lipgloss.NewStyle().Foreground(styleError).Bold(true).Render(text)
}
// row marks the active selection with a textual caret and, when color is
// available, a bold highlight padded to the content width. At reduced color
// profiles (ANSI/16-color) a background is omitted because lipgloss quantizes
// the adaptive surface to a colliding color (observed cyan-on-cyan); the caret
// plus bold stays readable. ANSI256/TrueColor keep the adaptive background.
func (s pickerStyles) row(text string, selected bool, width int) string {
marker := " "
if selected {
marker = "› "
}
if s.plain {
return marker + text
}
style := lipgloss.NewStyle()
if selected {
// termenv orders profiles by richness (TrueColor=0 ... Ascii=3), so a
// profile index at or above ANSI is a reduced-color terminal. Those keep
// the readable textual caret plus bold without the adaptive background
// (which lipgloss quantizes to a colliding color, e.g. cyan-on-cyan).
if lipgloss.ColorProfile() >= termenv.ANSI {
style = style.Bold(true)
} else {
style = style.Foreground(styleAccent).Background(styleSelection).Bold(true)
}
}
if width > 0 {
style = style.Width(width)
}
return style.Render(marker + text)
}
// wrap breaks prose into lines no wider than width, on word boundaries.
func wrap(text string, width int) []string {
if width < 1 {
width = 1
}
var lines []string
for _, paragraph := range strings.Split(text, "\n") {
words := strings.Fields(paragraph)
if len(words) == 0 {
lines = append(lines, "")
continue
}
line := words[0]
for _, word := range words[1:] {
if len(line)+1+len(word) > width {
lines = append(lines, line)
line = word
continue
}
line += " " + word
}
lines = append(lines, line)
}
return lines
}