tui

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	White = lipgloss.Color("#fff")
	Black = lipgloss.Color("#000")

	Blue      = lipgloss.Color("#0D6EFD")
	Blue100   = lipgloss.Color("#CFE2FF")
	Blue200   = lipgloss.Color("#9EC5FE")
	Blue300   = lipgloss.Color("#6EA8FE")
	Blue400   = lipgloss.Color("#3D8BFD")
	Blue500   = lipgloss.Color("#0D6EFD")
	Blue600   = lipgloss.Color("#0A58CA")
	Blue700   = lipgloss.Color("#084298")
	Blue800   = lipgloss.Color("#052C65")
	Blue900   = lipgloss.Color("#031633")
	Indigo    = lipgloss.Color("#6610F2")
	Indigo100 = lipgloss.Color("#E0CFFC")
	Indigo200 = lipgloss.Color("#C29FFA")
	Indigo300 = lipgloss.Color("#A370F7")
	Indigo400 = lipgloss.Color("#8540F5")
	Indigo500 = lipgloss.Color("#6610F2")
	Indigo600 = lipgloss.Color("#520DC2")
	Indigo700 = lipgloss.Color("#3D0A91")
	Indigo800 = lipgloss.Color("#290661")
	Indigo900 = lipgloss.Color("#140330")
	Purple    = lipgloss.Color("#6F42C1")
	Purple100 = lipgloss.Color("#E2D9F3")
	Purple200 = lipgloss.Color("#C5B3E6")
	Purple300 = lipgloss.Color("#A98EDA")
	Purple400 = lipgloss.Color("#8C68CD")
	Purple500 = lipgloss.Color("#6F42C1")
	Purple600 = lipgloss.Color("#59359A")
	Purple700 = lipgloss.Color("#432874")
	Purple800 = lipgloss.Color("#2C1A4D")
	Purple900 = lipgloss.Color("#160D27")
	Pink      = lipgloss.Color("#D63384")
	Pink100   = lipgloss.Color("#F7D6E6")
	Pink200   = lipgloss.Color("#EFADCE")
	Pink300   = lipgloss.Color("#E685B5")
	Pink400   = lipgloss.Color("#DE5C9D")
	Pink500   = lipgloss.Color("#D63384")
	Pink600   = lipgloss.Color("#AB296A")
	Pink700   = lipgloss.Color("#801F4F")
	Pink800   = lipgloss.Color("#561435")
	Pink900   = lipgloss.Color("#2B0A1A")
	Red       = lipgloss.Color("#DC3545")
	Red100    = lipgloss.Color("#F8D7DA")
	Red200    = lipgloss.Color("#F1AEB5")
	Red300    = lipgloss.Color("#EA868F")
	Red400    = lipgloss.Color("#E35D6A")
	Red500    = lipgloss.Color("#DC3545")
	Red600    = lipgloss.Color("#B02A37")
	Red700    = lipgloss.Color("#842029")
	Red800    = lipgloss.Color("#58151C")
	Red900    = lipgloss.Color("#2C0B0E")
	Orange    = lipgloss.Color("#FD7E14")
	Orange100 = lipgloss.Color("#FFE5D0")
	Orange200 = lipgloss.Color("#FECBA1")
	Orange300 = lipgloss.Color("#FEB272")
	Orange400 = lipgloss.Color("#FD9843")
	Orange500 = lipgloss.Color("#FD7E14")
	Orange600 = lipgloss.Color("#CA6510")
	Orange700 = lipgloss.Color("#984C0C")
	Orange800 = lipgloss.Color("#653208")
	Orange900 = lipgloss.Color("#331904")
	Yellow    = lipgloss.Color("#FFC107")
	Yellow100 = lipgloss.Color("#FFF3CD")
	Yellow200 = lipgloss.Color("#FFE69C")
	Yellow300 = lipgloss.Color("#FFDA6A")
	Yellow400 = lipgloss.Color("#FFCD39")
	Yellow500 = lipgloss.Color("#FFC107")
	Yellow600 = lipgloss.Color("#CC9A06")
	Yellow700 = lipgloss.Color("#997404")
	Yellow800 = lipgloss.Color("#664D03")
	Yellow900 = lipgloss.Color("#332701")
	Green     = lipgloss.Color("#198754")
	Green100  = lipgloss.Color("#D1E7DD")
	Green200  = lipgloss.Color("#A3CFBB")
	Green300  = lipgloss.Color("#75B798")
	Green400  = lipgloss.Color("#479F76")
	Green500  = lipgloss.Color("#198754")
	Green600  = lipgloss.Color("#146C43")
	Green700  = lipgloss.Color("#0F5132")
	Green800  = lipgloss.Color("#0A3622")
	Green900  = lipgloss.Color("#051B11")
	Teal      = lipgloss.Color("#20C997")
	Teal100   = lipgloss.Color("#D2F4EA")
	Teal200   = lipgloss.Color("#A6E9D5")
	Teal300   = lipgloss.Color("#79DFC1")
	Teal400   = lipgloss.Color("#4DD4AC")
	Teal500   = lipgloss.Color("#20C997")
	Teal600   = lipgloss.Color("#1AA179")
	Teal700   = lipgloss.Color("#13795B")
	Teal800   = lipgloss.Color("#0D503C")
	Teal900   = lipgloss.Color("#06281E")
	Cyan      = lipgloss.Color("#0DCAF0")
	Cyan100   = lipgloss.Color("#CFF4FC")
	Cyan200   = lipgloss.Color("#9EEAF9")
	Cyan300   = lipgloss.Color("#6EDFF6")
	Cyan400   = lipgloss.Color("#3DD5F3")
	Cyan500   = lipgloss.Color("#0DCAF0")
	Cyan600   = lipgloss.Color("#0AA2C0")
	Cyan700   = lipgloss.Color("#087990")
	Cyan800   = lipgloss.Color("#055160")
	Cyan900   = lipgloss.Color("#032830")
	Gray      = lipgloss.Color("#ADB5BD")
	Gray100   = lipgloss.Color("#EFF0F2")
	Gray200   = lipgloss.Color("#DEE1E5")
	Gray300   = lipgloss.Color("#CED3D7")
	Gray400   = lipgloss.Color("#BDC4CA")
	Gray500   = lipgloss.Color("#ADB5BD")
	Gray600   = lipgloss.Color("#8A9197")
	Gray700   = lipgloss.Color("#686D71")
	Gray800   = lipgloss.Color("#45484C")
	Gray900   = lipgloss.Color("#232426")
)
View Source
const (
	Stdout fileDescriptorKey = iota
	Stderr
)
View Source
const (
	Danger styleIdentifier = 1 << iota
	Dark
	Info
	Light
	NoColor
	Primary
	Secondary
	Success
	Warning
)

Variables

View Source
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]lipgloss.Color{}/* 110 elements not displayed */

)
View Source
var Bold = func(s *lipgloss.Style) {
	s.Bold(true)
}

Functions

func ColorProfileFromContext

func ColorProfileFromContext(ctx context.Context) termenv.Profile

func ColorToHex

func ColorToHex(in lipgloss.Color) string

func NewContext

func NewContext(ctx context.Context, stdout, stderr io.Writer) context.Context

func NewContextWithoutLogger

func NewContextWithoutLogger(ctx context.Context, stdout, stderr io.Writer) context.Context

func ParseLogLevel

func ParseLogLevel(name string, fallback slog.Level) slog.Level

func Replace

func Replace(color string) string

func ShadeColor

func ShadeColor(in string, percent float64) lipgloss.Color

func StringDump

func StringDump(key, value string) slog.Attr

func TintColor

func TintColor(in string, percent float64) lipgloss.Color

func TransformColor

func TransformColor(base, filter string, percent float64) string

func WritersFromContext

func WritersFromContext(ctx context.Context) (Writer, Writer)

Types

type ColorPair

type ColorPair struct {
	Name  string
	Value lipgloss.Color
}

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, renderer *lipgloss.Renderer, 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) Box

func (p Printer) Box(header string, bodies ...string)

Create a visual box with the printer style

func (Printer) BoxWidth

func (p Printer) BoxWidth() int

GetBoxWidth returns the configured [BoxWidth] for word wrapping

func (Printer) Copy

func (p Printer) Copy(options ...PrinterOption) Printer

func (Printer) Fprint

func (p Printer) Fprint(w io.Writer, a ...any) (n int, err error)

Fprint mirrors fmt.Fprint signature and behavior, with the configured style and (optional) word wrapping applied

func (Printer) Fprintf

func (p Printer) Fprintf(w io.Writer, format string, a ...any) (n int, err error)

Fprintf mirrors fmt.Fprintf signature and behavior, with the configured style and (optional) word wrapping applied

func (Printer) Fprintfln

func (p Printer) Fprintfln(w io.Writer, format string, a ...any) (n int, err error)

Fprintfln mirrors fmt.Fprintfln signature and behavior, with the configured style and (optional) word wrapping applied

func (Printer) Fprintln

func (p Printer) Fprintln(w io.Writer, a ...any) (n int, err error)

Fprintln mirrors fmt.Fprintln signature and behavior, with the configured style and (optional) word wrapping applied

func (Printer) GetWriter

func (p Printer) GetWriter() io.Writer

func (Printer) Print

func (p Printer) Print(a ...any) (n int, err error)

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

func (p Printer) Printf(format string, a ...any) (n int, err error)

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

func (p Printer) Printfln(format string, a ...any) (n int, err error)

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

func (p Printer) Println(a ...any) (n int, err error)

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

func (p Printer) Sprint(a ...any) string

Sprint mirrors fmt.Sprint signature and behavior, with the configured style and (optional) word wrapping applied.

func (Printer) Sprintf

func (p Printer) Sprintf(format string, a ...any) string

Sprintf mirrors fmt.Sprintf signature and behavior, with the configured style and (optional) word wrapping applied.

func (Printer) Sprintfln

func (p Printer) Sprintfln(format string, a ...any) string

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

func (p Printer) Sprintln(a ...any) string

Sprintln mirrors fmt.Sprintln signature and behavior, with the configured style and (optional) word wrapping applied.

func (Printer) Style

func (p Printer) Style() lipgloss.Style

TextStyle returns a *copy* of the current lipgloss.Style

func (Printer) Write

func (p Printer) Write(b []byte) (n int, err error)

func (Printer) Writer

func (p Printer) Writer() io.Writer

Writer returns the configured io.Writer

type PrinterOption

type PrinterOption func(p *Printer)

func WitBoxWidth

func WitBoxWidth(i int) PrinterOption

func WithEmphasis

func WithEmphasis(b bool) PrinterOption

func WithRenderer

func WithRenderer(renderer *lipgloss.Renderer) PrinterOption

func WithStyle

func WithStyle(style Style) PrinterOption

func WithTextStyle

func WithTextStyle(style lipgloss.Style) PrinterOption

func WithWriter

func WithWriter(w io.Writer) PrinterOption

type Style

type Style struct {
	// contains filtered or unexported fields
}

func NewStyle

func NewStyle(baseColor lipgloss.Color) Style

func NewStyleWithoutColor

func NewStyleWithoutColor() Style

func (Style) BoxBody

func (style Style) BoxBody() lipgloss.Style

func (Style) BoxHeader

func (style Style) BoxHeader() lipgloss.Style

func (Style) NewPrinter

func (style Style) NewPrinter(renderer *lipgloss.Renderer, options ...PrinterOption) Printer

func (Style) TextEmphasisStyle

func (style Style) TextEmphasisStyle() lipgloss.Style

func (Style) TextStyle

func (style Style) TextStyle() lipgloss.Style

type StyleChanger

type StyleChanger func(*lipgloss.Style)

type Theme

type Theme struct {
	// contains filtered or unexported fields
}

func NewTheme

func NewTheme() Theme

func ThemeFromContext

func ThemeFromContext(ctx context.Context) Theme

func (Theme) Style

func (theme Theme) Style(id styleIdentifier) Style

func (Theme) Writer

func (theme Theme) Writer(renderer *lipgloss.Renderer) Writer

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(ctx context.Context, writer io.Writer) Writer

func StderrFromContext

func StderrFromContext(ctx context.Context) Writer

func StdoutFromContext

func StdoutFromContext(ctx context.Context) Writer

func WriterFromContext

func WriterFromContext(ctx context.Context, descriptor fileDescriptorKey) Writer

func (Writer) Danger

func (w Writer) Danger() Printer

func (Writer) Dark

func (w Writer) Dark() Printer

func (Writer) Info

func (w Writer) Info() Printer

func (Writer) Light

func (w Writer) Light() Printer

func (Writer) NoColor

func (w Writer) NoColor() Printer

func (Writer) Primary

func (w Writer) Primary() Printer

func (Writer) Secondary

func (w Writer) Secondary() Printer

func (Writer) Style

func (w Writer) Style(colorType styleIdentifier) Printer

func (Writer) Success

func (w Writer) Success() Printer

func (Writer) Warning

func (w Writer) Warning() Printer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL