styles.go

 1package log
 2
 3import (
 4	"strings"
 5
 6	"github.com/charmbracelet/lipgloss/v2"
 7)
 8
 9// Styles defines the styles for the text logger.
10type Styles struct {
11	// Timestamp is the style for timestamps.
12	Timestamp lipgloss.Style
13
14	// Caller is the style for source caller.
15	Caller lipgloss.Style
16
17	// Prefix is the style for prefix.
18	Prefix lipgloss.Style
19
20	// Message is the style for messages.
21	Message lipgloss.Style
22
23	// Key is the style for keys.
24	Key lipgloss.Style
25
26	// Value is the style for values.
27	Value lipgloss.Style
28
29	// Separator is the style for separators.
30	Separator lipgloss.Style
31
32	// Levels are the styles for each level.
33	Levels map[Level]lipgloss.Style
34
35	// Keys overrides styles for specific keys.
36	Keys map[string]lipgloss.Style
37
38	// Values overrides value styles for specific keys.
39	Values map[string]lipgloss.Style
40}
41
42// DefaultStyles returns the default styles.
43func DefaultStyles() *Styles {
44	// TODO handle this based on light/dark colors
45	return &Styles{
46		Timestamp: lipgloss.NewStyle(),
47		Caller:    lipgloss.NewStyle().Faint(true),
48		Prefix:    lipgloss.NewStyle().Bold(true).Faint(true),
49		Message:   lipgloss.NewStyle(),
50		Key:       lipgloss.NewStyle().Faint(true),
51		Value:     lipgloss.NewStyle(),
52		Separator: lipgloss.NewStyle().Faint(true),
53		Levels: map[Level]lipgloss.Style{
54			DebugLevel: lipgloss.NewStyle().
55				SetString(strings.ToUpper(DebugLevel.String())).
56				Bold(true).
57				MaxWidth(4).
58				Foreground(lipgloss.Color("63")),
59			InfoLevel: lipgloss.NewStyle().
60				SetString(strings.ToUpper(InfoLevel.String())).
61				Bold(true).
62				MaxWidth(4).
63				Foreground(lipgloss.Color("86")),
64			WarnLevel: lipgloss.NewStyle().
65				SetString(strings.ToUpper(WarnLevel.String())).
66				Bold(true).
67				MaxWidth(4).
68				Foreground(lipgloss.Color("192")),
69			ErrorLevel: lipgloss.NewStyle().
70				SetString(strings.ToUpper(ErrorLevel.String())).
71				Bold(true).
72				MaxWidth(4).
73				Foreground(lipgloss.Color("204")),
74			FatalLevel: lipgloss.NewStyle().
75				SetString(strings.ToUpper(FatalLevel.String())).
76				Bold(true).
77				MaxWidth(4).
78				Foreground(lipgloss.Color("134")),
79		},
80		Keys:   map[string]lipgloss.Style{},
81		Values: map[string]lipgloss.Style{},
82	}
83}