package ui
import (
)
type ColorMode string
const (
ColorAuto ColorMode = "auto"
ColorAlways ColorMode = "always"
ColorNever ColorMode = "never"
)
func ( string) (ColorMode, error) {
switch := ColorMode(); {
case "", ColorAuto:
return ColorAuto, nil
case ColorAlways, ColorNever:
return , nil
default:
return "", fmt.Errorf("invalid color mode %q (expected auto, always, or never)", )
}
}
type Format string
const (
FormatText Format = "text"
FormatJSON Format = "json"
FormatDOT Format = "dot"
FormatMermaid Format = "mermaid"
)
type Renderer struct {
out *colorprofile.Writer
styles palette
}
type palette struct {
title lipgloss.Style
subtle lipgloss.Style
layer lipgloss.Style
module lipgloss.Style
version lipgloss.Style
tag lipgloss.Style
commit lipgloss.Style
ok lipgloss.Style
warn lipgloss.Style
border lipgloss.Style
header lipgloss.Style
}
func ( io.Writer, ColorMode, []string) *Renderer {
:= colorprofile.NewWriter(, )
switch {
case ColorNever:
.Profile = colorprofile.Ascii
case ColorAlways:
if .Profile == colorprofile.Ascii || .Profile == colorprofile.NoTTY {
.Profile = colorprofile.TrueColor
}
}
return &Renderer{
out: ,
styles: palette{
title: lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12")),
subtle: lipgloss.NewStyle().Foreground(lipgloss.Color("8")),
layer: lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("14")),
module: lipgloss.NewStyle().Bold(true),
version: lipgloss.NewStyle().Foreground(lipgloss.Color("10")),
tag: lipgloss.NewStyle().Foreground(lipgloss.Color("11")),
commit: lipgloss.NewStyle().Foreground(lipgloss.Color("13")),
ok: lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("10")),
warn: lipgloss.NewStyle().Foreground(lipgloss.Color("11")),
border: lipgloss.NewStyle().Foreground(lipgloss.Color("8")),
header: lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12")).Padding(0, 1),
},
}
}
func ( io.Writer, any) error {
, := json.Marshal(, jsontext.WithIndent(" "))
if != nil {
return
}
_, = fmt.Fprintf(, "%s\n", )
return
}
func ( string) string {
if len() > 10 {
return [:10]
}
return
}