Repository navigation
Expand file tree
/
Copy paththeme.go
More file actions
116 lines (108 loc) · 3.1 KB
/
Copy paththeme.go
File metadata and controls
116 lines (108 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package stackparse
import "github.com/charmbracelet/lipgloss"
// StyleDisabler represents types that can disable their styles
type StyleDisabler interface {
DisableStyles()
}
// Theme defines the styling for different components
//
// You can provide you own theme to stackparse, and all of the output will be styled accordingly
// Setting a custom DisableStylesFunc is not required but if you want to preserve specific styling, you can do so.
// Usage would look something like this.
//
// Method 1: Using SetDisableStylesFunc:
// theme := stackparse.DefaultTheme()
// theme.SetDisableStylesFunc(func(t *stackparse.Theme) {
// // Custom implementation
// t.Base = t.Base.UnsetForeground()
// t.Function = t.Function.UnsetBold()
// // ... other custom unset operations
// })
//
// Method 2: Creating a custom theme with custom disable function:
// customTheme := &stackparse.Theme{
// // ... theme settings ...
// }
// customTheme.SetDisableStylesFunc(func(t *stackparse.Theme) {
// // Custom implementation
// })
type Theme struct {
Base lipgloss.Style
Goroutine lipgloss.Style
Function lipgloss.Style
Args lipgloss.Style
File lipgloss.Style
Line lipgloss.Style
CreatedBy lipgloss.Style
Repeat lipgloss.Style
// Optional custom disable function
disableStylesFunc func(*Theme)
}
// DisableStyles disables all color and text styles (e.g. bold, underline, etc.) of a theme
//
// When providing your own theme, you can use this default or create your own DisableStyles to unset only specific styling.
//
// Keep in mind you need to reassign the styles after unsetting parts of them, for example:
// func (t *Theme) DisableStyles() {
// t.Base = t.Base.UnsetForeground()
// }
//
func (t *Theme) DisableStyles() {
if t.disableStylesFunc != nil {
t.disableStylesFunc(t)
return
}
// Default implementation that disables everything
for _, field := range []*lipgloss.Style{
&t.Base,
&t.Goroutine,
&t.Function,
&t.Args,
&t.File,
&t.Line,
&t.CreatedBy,
&t.Repeat,
} {
*field = field.
UnsetForeground().
UnsetBackground().
UnsetBold().
UnsetFaint().
UnsetItalic().
UnsetBlink()
}
}
// SetDisableStylesFunc allows setting a custom DisableStyles implementation
//
// For more info read the documentation of
// Theme{}
func (t *Theme) SetDisableStylesFunc(f func(*Theme)) {
t.disableStylesFunc = f
}
// DefaultTheme returns the default styling theme
func DefaultTheme() *Theme {
return &Theme{
Base: lipgloss.NewStyle().PaddingLeft(2),
Goroutine: lipgloss.NewStyle().
Bold(true).
// Foreground(lipgloss.Color("#00ADD8")).
Foreground(lipgloss.Color("#ed8796")).
MarginTop(1),
// MarginBottom(1),
Function: lipgloss.NewStyle().
Foreground(lipgloss.Color("#f0c6c6")),
Args: lipgloss.NewStyle().
Foreground(lipgloss.Color("#7dc4e4")).
PaddingLeft(2),
File: lipgloss.NewStyle().
Foreground(lipgloss.Color("#f5a97f")),
Line: lipgloss.NewStyle().
Foreground(lipgloss.Color("#eed49f")),
// PaddingLeft(2),
CreatedBy: lipgloss.NewStyle().
Foreground(lipgloss.Color("#ee99a0")),
Repeat: lipgloss.NewStyle().
Italic(true).
Faint(true),
}
}