Documentation
¶
Index ¶
- Constants
- Variables
- func ColorProfileFromContext(ctx context.Context) termenv.Profile
- func NewContext(ctx context.Context, stdout, stderr io.Writer) context.Context
- func NewContextWithoutLogger(ctx context.Context, stdout, stderr io.Writer) context.Context
- func ParseLogLevel(name string, fallback slog.Level) slog.Level
- func ShadeColor(in string, percent float64) string
- func StringDump(key, value string) slog.Attr
- func TintColor(in string, percent float64) string
- func TransformColor(base, filter string, percent float64) string
- func WritersFromContext(ctx context.Context) (Writer, Writer)
- type ColorPair
- type Printer
- func (p Printer) ApplyStyle(callback StyleChanger) Printer
- func (p Printer) Box(header string, bodies ...string)
- func (p Printer) BoxWidth() int
- func (p Printer) Copy(options ...PrinterOption) Printer
- func (p Printer) Fprint(w io.Writer, a ...any) (n int, err error)
- func (p Printer) Fprintf(w io.Writer, format string, a ...any) (n int, err error)
- func (p Printer) Fprintfln(w io.Writer, format string, a ...any) (n int, err error)
- func (p Printer) Fprintln(w io.Writer, a ...any) (n int, err error)
- func (p Printer) GetWriter() io.Writer
- func (p Printer) Print(a ...any) (n int, err error)
- func (p Printer) Printf(format string, a ...any) (n int, err error)
- func (p Printer) Printfln(format string, a ...any) (n int, err error)
- func (p Printer) Println(a ...any) (n int, err error)
- func (p Printer) Sprint(a ...any) string
- func (p Printer) Sprintf(format string, a ...any) string
- func (p Printer) Sprintfln(format string, a ...any) string
- func (p Printer) Sprintln(a ...any) string
- func (p Printer) Style() lipgloss.Style
- func (p Printer) Write(b []byte) (n int, err error)
- func (p Printer) Writer() io.Writer
- type PrinterOption
- type Style
- type StyleChanger
- type Theme
- type Writer
- func (w Writer) Danger() Printer
- func (w Writer) Dark() Printer
- func (w Writer) GetWriter() io.Writer
- func (w Writer) Info() Printer
- func (w Writer) Light() Printer
- func (w Writer) NoColor() Printer
- func (w Writer) Primary() Printer
- func (w Writer) Secondary() Printer
- func (w Writer) Style(colorType styleIdentifier) Printer
- func (w Writer) Success() Printer
- func (w Writer) Warning() Printer
Constants ¶
const ( White = "#fff" Black = "#000" Blue = "#0D6EFD" Blue100 = "#CFE2FF" Blue200 = "#9EC5FE" Blue300 = "#6EA8FE" Blue400 = "#3D8BFD" Blue500 = "#0D6EFD" Blue600 = "#0A58CA" Blue700 = "#084298" Blue800 = "#052C65" Blue900 = "#031633" Indigo = "#6610F2" Indigo100 = "#E0CFFC" Indigo200 = "#C29FFA" Indigo300 = "#A370F7" Indigo400 = "#8540F5" Indigo500 = "#6610F2" Indigo600 = "#520DC2" Indigo700 = "#3D0A91" Indigo800 = "#290661" Indigo900 = "#140330" Purple = "#6F42C1" Purple100 = "#E2D9F3" Purple200 = "#C5B3E6" Purple300 = "#A98EDA" Purple400 = "#8C68CD" Purple500 = "#6F42C1" Purple600 = "#59359A" Purple700 = "#432874" Purple800 = "#2C1A4D" Purple900 = "#160D27" Pink = "#D63384" Pink100 = "#F7D6E6" Pink200 = "#EFADCE" Pink300 = "#E685B5" Pink400 = "#DE5C9D" Pink500 = "#D63384" Pink600 = "#AB296A" Pink700 = "#801F4F" Pink800 = "#561435" Pink900 = "#2B0A1A" Red = "#DC3545" Red100 = "#F8D7DA" Red200 = "#F1AEB5" Red300 = "#EA868F" Red400 = "#E35D6A" Red500 = "#DC3545" Red600 = "#B02A37" Red700 = "#842029" Red800 = "#58151C" Red900 = "#2C0B0E" Orange = "#FD7E14" Orange100 = "#FFE5D0" Orange200 = "#FECBA1" Orange300 = "#FEB272" Orange400 = "#FD9843" Orange500 = "#FD7E14" Orange600 = "#CA6510" Orange700 = "#984C0C" Orange800 = "#653208" Orange900 = "#331904" Yellow = "#FFC107" Yellow100 = "#FFF3CD" Yellow200 = "#FFE69C" Yellow300 = "#FFDA6A" Yellow400 = "#FFCD39" Yellow500 = "#FFC107" Yellow600 = "#CC9A06" Yellow700 = "#997404" Yellow800 = "#664D03" Yellow900 = "#332701" Green = "#198754" Green100 = "#D1E7DD" Green200 = "#A3CFBB" Green300 = "#75B798" Green400 = "#479F76" Green500 = "#198754" Green600 = "#146C43" Green700 = "#0F5132" Green800 = "#0A3622" Green900 = "#051B11" Teal = "#20C997" Teal100 = "#D2F4EA" Teal200 = "#A6E9D5" Teal300 = "#79DFC1" Teal400 = "#4DD4AC" Teal500 = "#20C997" Teal600 = "#1AA179" Teal700 = "#13795B" Teal800 = "#0D503C" Teal900 = "#06281E" Cyan = "#0DCAF0" Cyan100 = "#CFF4FC" Cyan200 = "#9EEAF9" Cyan300 = "#6EDFF6" Cyan400 = "#3DD5F3" Cyan500 = "#0DCAF0" Cyan600 = "#0AA2C0" Cyan700 = "#087990" Cyan800 = "#055160" Cyan900 = "#032830" Gray = "#ADB5BD" Gray100 = "#EFF0F2" Gray200 = "#DEE1E5" Gray300 = "#CED3D7" Gray400 = "#BDC4CA" Gray500 = "#ADB5BD" Gray600 = "#8A9197" Gray700 = "#686D71" Gray800 = "#45484C" Gray900 = "#232426" )
const ( Stdout fileDescriptorKey = iota Stderr )
const ( Danger styleIdentifier = 1 << iota Dark Info Light NoColor Primary Secondary Success Warning )
Variables ¶
var ( BlueFamily = []ColorPair{ { Name: "Blue100", Value: Blue100, }, { Name: "Blue200", Value: Blue200, }, { Name: "Blue300", Value: Blue300, }, { Name: "Blue400", Value: Blue400, }, { Name: "Blue500", Value: Blue500, }, { Name: "Blue600", Value: Blue600, }, { Name: "Blue700", Value: Blue700, }, { Name: "Blue800", Value: Blue800, }, { Name: "Blue900", Value: Blue900, }, } IndigoFamily = []ColorPair{ { Name: "Indigo100", Value: Indigo100, }, { Name: "Indigo200", Value: Indigo200, }, { Name: "Indigo300", Value: Indigo300, }, { Name: "Indigo400", Value: Indigo400, }, { Name: "Indigo500", Value: Indigo500, }, { Name: "Indigo600", Value: Indigo600, }, { Name: "Indigo700", Value: Indigo700, }, { Name: "Indigo800", Value: Indigo800, }, { Name: "Indigo900", Value: Indigo900, }, } PurpleFamily = []ColorPair{ { Name: "Purple100", Value: Purple100, }, { Name: "Purple200", Value: Purple200, }, { Name: "Purple300", Value: Purple300, }, { Name: "Purple400", Value: Purple400, }, { Name: "Purple500", Value: Purple500, }, { Name: "Purple600", Value: Purple600, }, { Name: "Purple700", Value: Purple700, }, { Name: "Purple800", Value: Purple800, }, { Name: "Purple900", Value: Purple900, }, } PinkFamily = []ColorPair{ { Name: "Pink100", Value: Pink100, }, { Name: "Pink200", Value: Pink200, }, { Name: "Pink300", Value: Pink300, }, { Name: "Pink400", Value: Pink400, }, { Name: "Pink500", Value: Pink500, }, { Name: "Pink600", Value: Pink600, }, { Name: "Pink700", Value: Pink700, }, { Name: "Pink800", Value: Pink800, }, { Name: "Pink900", Value: Pink900, }, } RedFamily = []ColorPair{ { Name: "Red100", Value: Red100, }, { Name: "Red200", Value: Red200, }, { Name: "Red300", Value: Red300, }, { Name: "Red400", Value: Red400, }, { Name: "Red500", Value: Red500, }, { Name: "Red600", Value: Red600, }, { Name: "Red700", Value: Red700, }, { Name: "Red800", Value: Red800, }, { Name: "Red900", Value: Red900, }, } OrangeFamily = []ColorPair{ { Name: "Orange100", Value: Orange100, }, { Name: "Orange200", Value: Orange200, }, { Name: "Orange300", Value: Orange300, }, { Name: "Orange400", Value: Orange400, }, { Name: "Orange500", Value: Orange500, }, { Name: "Orange600", Value: Orange600, }, { Name: "Orange700", Value: Orange700, }, { Name: "Orange800", Value: Orange800, }, { Name: "Orange900", Value: Orange900, }, } YellowFamily = []ColorPair{ { Name: "Yellow100", Value: Yellow100, }, { Name: "Yellow200", Value: Yellow200, }, { Name: "Yellow300", Value: Yellow300, }, { Name: "Yellow400", Value: Yellow400, }, { Name: "Yellow500", Value: Yellow500, }, { Name: "Yellow600", Value: Yellow600, }, { Name: "Yellow700", Value: Yellow700, }, { Name: "Yellow800", Value: Yellow800, }, { Name: "Yellow900", Value: Yellow900, }, } GreenFamily = []ColorPair{ { Name: "Green100", Value: Green100, }, { Name: "Green200", Value: Green200, }, { Name: "Green300", Value: Green300, }, { Name: "Green400", Value: Green400, }, { Name: "Green500", Value: Green500, }, { Name: "Green600", Value: Green600, }, { Name: "Green700", Value: Green700, }, { Name: "Green800", Value: Green800, }, { Name: "Green900", Value: Green900, }, } TealFamily = []ColorPair{ { Name: "Teal100", Value: Teal100, }, { Name: "Teal200", Value: Teal200, }, { Name: "Teal300", Value: Teal300, }, { Name: "Teal400", Value: Teal400, }, { Name: "Teal500", Value: Teal500, }, { Name: "Teal600", Value: Teal600, }, { Name: "Teal700", Value: Teal700, }, { Name: "Teal800", Value: Teal800, }, { Name: "Teal900", Value: Teal900, }, } CyanFamily = []ColorPair{ { Name: "Cyan100", Value: Cyan100, }, { Name: "Cyan200", Value: Cyan200, }, { Name: "Cyan300", Value: Cyan300, }, { Name: "Cyan400", Value: Cyan400, }, { Name: "Cyan500", Value: Cyan500, }, { Name: "Cyan600", Value: Cyan600, }, { Name: "Cyan700", Value: Cyan700, }, { Name: "Cyan800", Value: Cyan800, }, { Name: "Cyan900", Value: Cyan900, }, } GrayFamily = []ColorPair{ { Name: "Gray100", Value: Gray100, }, { Name: "Gray200", Value: Gray200, }, { Name: "Gray300", Value: Gray300, }, { Name: "Gray400", Value: Gray400, }, { Name: "Gray500", Value: Gray500, }, { Name: "Gray600", Value: Gray600, }, { Name: "Gray700", Value: Gray700, }, { Name: "Gray800", Value: Gray800, }, { Name: "Gray900", Value: Gray900, }, } ColorsFamilies = []string{ "Blue", "Indigo", "Purple", "Pink", "Red", "Orange", "Yellow", "Green", "Teal", "Cyan", "Gray", } // All colors, grouped by their family ColorsByFamily = map[string][]ColorPair{ "Blue": BlueFamily, "Indigo": IndigoFamily, "Purple": PurpleFamily, "Pink": PinkFamily, "Red": RedFamily, "Orange": OrangeFamily, "Yellow": YellowFamily, "Green": GreenFamily, "Teal": TealFamily, "Cyan": CyanFamily, "Gray": GrayFamily, } // All known colors in a map to easily look up their name to value AllColors = map[string]string{ "Blue100": Blue100, "Blue200": Blue200, "Blue300": Blue300, "Blue400": Blue400, "Blue500": Blue500, "Blue600": Blue600, "Blue700": Blue700, "Blue800": Blue800, "Blue900": Blue900, "Indigo100": Indigo100, "Indigo200": Indigo200, "Indigo300": Indigo300, "Indigo400": Indigo400, "Indigo500": Indigo500, "Indigo600": Indigo600, "Indigo700": Indigo700, "Indigo800": Indigo800, "Indigo900": Indigo900, "Purple100": Purple100, "Purple200": Purple200, "Purple300": Purple300, "Purple400": Purple400, "Purple500": Purple500, "Purple600": Purple600, "Purple700": Purple700, "Purple800": Purple800, "Purple900": Purple900, "Pink100": Pink100, "Pink200": Pink200, "Pink300": Pink300, "Pink400": Pink400, "Pink500": Pink500, "Pink600": Pink600, "Pink700": Pink700, "Pink800": Pink800, "Pink900": Pink900, "Red100": Red100, "Red200": Red200, "Red300": Red300, "Red400": Red400, "Red500": Red500, "Red600": Red600, "Red700": Red700, "Red800": Red800, "Red900": Red900, "Orange100": Orange100, "Orange200": Orange200, "Orange300": Orange300, "Orange400": Orange400, "Orange500": Orange500, "Orange600": Orange600, "Orange700": Orange700, "Orange800": Orange800, "Orange900": Orange900, "Yellow100": Yellow100, "Yellow200": Yellow200, "Yellow300": Yellow300, "Yellow400": Yellow400, "Yellow500": Yellow500, "Yellow600": Yellow600, "Yellow700": Yellow700, "Yellow800": Yellow800, "Yellow900": Yellow900, "Green100": Green100, "Green200": Green200, "Green300": Green300, "Green400": Green400, "Green500": Green500, "Green600": Green600, "Green700": Green700, "Green800": Green800, "Green900": Green900, "Teal100": Teal100, "Teal200": Teal200, "Teal300": Teal300, "Teal400": Teal400, "Teal500": Teal500, "Teal600": Teal600, "Teal700": Teal700, "Teal800": Teal800, "Teal900": Teal900, "Cyan100": Cyan100, "Cyan200": Cyan200, "Cyan300": Cyan300, "Cyan400": Cyan400, "Cyan500": Cyan500, "Cyan600": Cyan600, "Cyan700": Cyan700, "Cyan800": Cyan800, "Cyan900": Cyan900, "Gray100": Gray100, "Gray200": Gray200, "Gray300": Gray300, "Gray400": Gray400, "Gray500": Gray500, "Gray600": Gray600, "Gray700": Gray700, "Gray800": Gray800, "Gray900": Gray900, } )
var AlphaMap = map[int]string{}/* 101 elements not displayed */
var Bold = func(s *lipgloss.Style) { *s = s.Bold(true) }
Functions ¶
func ColorProfileFromContext ¶ added in v0.8.0
func NewContext ¶ added in v0.8.0
func NewContextWithoutLogger ¶ added in v0.9.4
func ParseLogLevel ¶ added in v0.9.4
func ShadeColor ¶
func StringDump ¶ added in v0.9.4
func TransformColor ¶ added in v0.8.0
Types ¶
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer mirrors the fmt package print/sprint functions, wraps them in a lipgloss.Style and an optional [WordWrap] configuration with a configured [BoxWidth].
Additionally, [Printer*] methods writes to the configured Writer instead of os.Stdout
func NewPrinter ¶
func NewPrinter(style Style, w io.Writer, options ...PrinterOption) Printer
func (Printer) ApplyStyle ¶
func (p Printer) ApplyStyle(callback StyleChanger) Printer
ApplyTextStyle returns a new copy of [StylePrint] instance with the Style based on the callback changes
func (Printer) BoxWidth ¶ added in v0.8.0
GetBoxWidth returns the configured [BoxWidth] for word wrapping
func (Printer) Copy ¶
func (p Printer) Copy(options ...PrinterOption) Printer
func (Printer) Fprint ¶
Fprint mirrors fmt.Fprint signature and behavior, with the configured style and (optional) word wrapping applied
func (Printer) Fprintf ¶
Fprintf mirrors fmt.Fprintf signature and behavior, with the configured style and (optional) word wrapping applied
func (Printer) Fprintfln ¶
Fprintfln mirrors fmt.Fprintfln signature and behavior, with the configured style and (optional) word wrapping applied
func (Printer) Fprintln ¶
Fprintln mirrors fmt.Fprintln signature and behavior, with the configured style and (optional) word wrapping applied
func (Printer) Print ¶
Print mirrors fmt.Print signature and behavior, with the configured style and (optional) word wrapping applied.
Instead of writing to os.Stdout it will write to the configured io.Writer.
func (Printer) Printf ¶
Printf mirrors fmt.Printf signature and behavior, with the configured style and (optional) word wrapping applied.
Instead of writing to os.Stdout it will write to the configured io.Writer.
func (Printer) Printfln ¶
Printfln behaves like fmt.Printf but supports the [formatter] signature.
This does *not* map to a Go native printer, but a mix for formatting + newline
func (Printer) Println ¶
Println mirrors fmt.Println signature and behavior, with the configured style and (optional) word wrapping applied.
Instead of writing to os.Stdout it will write to the configured io.Writer
func (Printer) Sprint ¶
Sprint mirrors fmt.Sprint signature and behavior, with the configured style and (optional) word wrapping applied.
func (Printer) Sprintf ¶
Sprintf mirrors fmt.Sprintf signature and behavior, with the configured style and (optional) word wrapping applied.
func (Printer) Sprintfln ¶
Sprintfln behaves like fmt.Sprintln but supports the [formatter] signature.
This does *not* map to a Go native printer, but a mix for formatting + newline
func (Printer) Sprintln ¶
Sprintln mirrors fmt.Sprintln signature and behavior, with the configured style and (optional) word wrapping applied.
func (Printer) Style ¶
TextStyle returns a *copy* of the current lipgloss.Style
type PrinterOption ¶
type PrinterOption func(p *Printer)
func WitBoxWidth ¶ added in v0.8.0
func WitBoxWidth(i int) PrinterOption
func WithEmphasis ¶
func WithEmphasis(b bool) PrinterOption
func WithStyle ¶ added in v0.8.0
func WithStyle(style Style) PrinterOption
func WithTextStyle ¶
func WithTextStyle(style lipgloss.Style) PrinterOption
func WithWriter ¶
func WithWriter(w io.Writer) PrinterOption
type Style ¶ added in v0.8.0
type Style struct {
// contains filtered or unexported fields
}
func NewStyleWithoutColor ¶ added in v0.8.0
func NewStyleWithoutColor() Style
func (Style) NewPrinter ¶ added in v0.8.0
func (style Style) NewPrinter(w io.Writer, options ...PrinterOption) Printer
func (Style) TextEmphasisStyle ¶ added in v0.8.0
type StyleChanger ¶
type Theme ¶
type Theme struct {
// contains filtered or unexported fields
}
func ThemeFromContext ¶ added in v0.8.0
type Writer ¶ added in v0.8.0
type Writer struct {
// contains filtered or unexported fields
}