color

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: BSD-2-Clause-Views Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoColor = noColorIsSet() || os.Getenv("TERM") == "dumb" ||
		(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
)

Functions

This section is empty.

Types

type Color

type Color struct {
	*color.Color
	Params  []color.Attribute
	NoColor *bool
}

Almost all codes are from "github.com/fatih/color"

func NewColor

func NewColor(value ...color.Attribute) *Color

func (*Color) Add

func (c *Color) Add(value ...color.Attribute) *Color

func (*Color) AppendFormat

func (c *Color) AppendFormat(b []byte) []byte

func (*Color) AppendUnformat

func (c *Color) AppendUnformat(b []byte) []byte

type ColorHandler

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

func NewHandler

func NewHandler(w io.Writer, opts *HandlerOptions, scheme *Scheme) *ColorHandler

func (*ColorHandler) Enabled

func (h *ColorHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ColorHandler) Handle

func (h *ColorHandler) Handle(ctx context.Context, r slog.Record) error

func (*ColorHandler) WithAttrs

func (h *ColorHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ColorHandler) WithGroup

func (h *ColorHandler) WithGroup(name string) slog.Handler

type Colorizer

type Colorizer interface {
	AppendFormat(b []byte) []byte
	AppendUnformat(b []byte) []byte
}

type HandlerOptions added in v0.3.0

type HandlerOptions struct {
	// from slog.HandlerOptions
	AddSource   bool
	Level       slog.Leveler
	ReplaceAttr func([]string, slog.Attr) slog.Attr

	Compat bool
}

type Scheme

type Scheme struct {
	Base Colorizer

	Level     map[slog.Level]Colorizer
	Time      Colorizer
	Source    Colorizer
	Message   Colorizer
	AttrKey   Colorizer
	AttrValue Colorizer
}

func DefaultDarkScheme

func DefaultDarkScheme() *Scheme

func DefaultLightScheme

func DefaultLightScheme() *Scheme

func DefaultNilScheme

func DefaultNilScheme() *Scheme

func (Scheme) AttrKeyPrinter

func (s Scheme) AttrKeyPrinter() Colorizer

func (Scheme) AttrValuePrinter

func (s Scheme) AttrValuePrinter() Colorizer

func (Scheme) BasePrinter

func (s Scheme) BasePrinter() Colorizer

func (Scheme) LevelPrinter

func (s Scheme) LevelPrinter(level slog.Level) Colorizer

func (Scheme) MessagePrinter

func (s Scheme) MessagePrinter() Colorizer

func (Scheme) SourcePrinter

func (s Scheme) SourcePrinter() Colorizer

func (Scheme) TimePrinter

func (s Scheme) TimePrinter() Colorizer

Jump to

Keyboard shortcuts

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