on main help sign in
refactor(diffview): wrap default styles into functions
34fa3c1Andrey Nering
internal/exp/diffview/diffview.go+1−1
@@ -69,7 +69,7 @@ func New() *DiffView {
69 lineNumbers: true,
69 lineNumbers: true,
70 tabWidth: 8,
70 tabWidth: 8,
71 }
71 }
72− dv.style = DefaultDarkStyle
72+ dv.style = DefaultDarkStyle()
73 return dv
73 return dv
74}
74}
75
75
internal/exp/diffview/diffview_test.go+7−7
@@ -97,12 +97,12 @@ var (
97
97
98 LightModeFunc = func(dv *diffview.DiffView) *diffview.DiffView {
98 LightModeFunc = func(dv *diffview.DiffView) *diffview.DiffView {
99 return dv.
99 return dv.
100− Style(diffview.DefaultLightStyle).
100+ Style(diffview.DefaultLightStyle()).
101 ChromaStyle(styles.Get("catppuccin-latte"))
101 ChromaStyle(styles.Get("catppuccin-latte"))
102 }
102 }
103 DarkModeFunc = func(dv *diffview.DiffView) *diffview.DiffView {
103 DarkModeFunc = func(dv *diffview.DiffView) *diffview.DiffView {
104 return dv.
104 return dv.
105− Style(diffview.DefaultDarkStyle).
105+ Style(diffview.DefaultDarkStyle()).
106 ChromaStyle(styles.Get("catppuccin-macchiato"))
106 ChromaStyle(styles.Get("catppuccin-macchiato"))
107 }
107 }
108
108
@@ -165,7 +165,7 @@ func TestDiffViewTabs(t *testing.T) {
165 dv := diffview.New().
165 dv := diffview.New().
166 Before("main.go", TestTabsBefore).
166 Before("main.go", TestTabsBefore).
167 After("main.go", TestTabsAfter).
167 After("main.go", TestTabsAfter).
168− Style(diffview.DefaultLightStyle).
168+ Style(diffview.DefaultLightStyle()).
169 ChromaStyle(styles.Get("catppuccin-latte"))
169 ChromaStyle(styles.Get("catppuccin-latte"))
170 dv = layoutFunc(dv)
170 dv = layoutFunc(dv)
171
171
@@ -190,7 +190,7 @@ func TestDiffViewWidth(t *testing.T) {
190 Before("main.go", TestMultipleHunksBefore).
190 Before("main.go", TestMultipleHunksBefore).
191 After("main.go", TestMultipleHunksAfter).
191 After("main.go", TestMultipleHunksAfter).
192 Width(width).
192 Width(width).
193− Style(diffview.DefaultLightStyle).
193+ Style(diffview.DefaultLightStyle()).
194 ChromaStyle(styles.Get("catppuccin-latte"))
194 ChromaStyle(styles.Get("catppuccin-latte"))
195 dv = layoutFunc(dv)
195 dv = layoutFunc(dv)
196
196
@@ -215,7 +215,7 @@ func TestDiffViewHeight(t *testing.T) {
215 Before("main.go", TestMultipleHunksBefore).
215 Before("main.go", TestMultipleHunksBefore).
216 After("main.go", TestMultipleHunksAfter).
216 After("main.go", TestMultipleHunksAfter).
217 Height(height).
217 Height(height).
218− Style(diffview.DefaultLightStyle).
218+ Style(diffview.DefaultLightStyle()).
219 ChromaStyle(styles.Get("catppuccin-latte"))
219 ChromaStyle(styles.Get("catppuccin-latte"))
220 dv = layoutFunc(dv)
220 dv = layoutFunc(dv)
221
221
@@ -239,7 +239,7 @@ func TestDiffViewXOffset(t *testing.T) {
239 dv := diffview.New().
239 dv := diffview.New().
240 Before("main.go", TestDefaultBefore).
240 Before("main.go", TestDefaultBefore).
241 After("main.go", TestDefaultAfter).
241 After("main.go", TestDefaultAfter).
242− Style(diffview.DefaultLightStyle).
242+ Style(diffview.DefaultLightStyle()).
243 ChromaStyle(styles.Get("catppuccin-latte")).
243 ChromaStyle(styles.Get("catppuccin-latte")).
244 Width(60).
244 Width(60).
245 XOffset(xOffset)
245 XOffset(xOffset)
@@ -265,7 +265,7 @@ func TestDiffViewYOffset(t *testing.T) {
265 dv := diffview.New().
265 dv := diffview.New().
266 Before("main.go", TestMultipleHunksBefore).
266 Before("main.go", TestMultipleHunksBefore).
267 After("main.go", TestMultipleHunksAfter).
267 After("main.go", TestMultipleHunksAfter).
268− Style(diffview.DefaultLightStyle).
268+ Style(diffview.DefaultLightStyle()).
269 ChromaStyle(styles.Get("catppuccin-latte")).
269 ChromaStyle(styles.Get("catppuccin-latte")).
270 Height(5).
270 Height(5).
271 YOffset(yOffset)
271 YOffset(yOffset)
internal/exp/diffview/style.go+94−90
@@ -24,97 +24,101 @@ type Style struct {
24}
24}
25
25
26// DefaultLightStyle provides a default light theme style for the diff view.
26// DefaultLightStyle provides a default light theme style for the diff view.
27−var DefaultLightStyle = Style{
27+func DefaultLightStyle() Style {
28+ return Style{
28− DividerLine: LineStyle{
29+ DividerLine: LineStyle{
29− LineNumber: lipgloss.NewStyle().
30+ LineNumber: lipgloss.NewStyle().
30− Foreground(charmtone.Iron).
31+ Foreground(charmtone.Iron).
31− Background(charmtone.Thunder),
32+ Background(charmtone.Thunder),
32− Code: lipgloss.NewStyle().
33+ Code: lipgloss.NewStyle().
33− Foreground(charmtone.Oyster).
34+ Foreground(charmtone.Oyster).
34− Background(charmtone.Anchovy),
35+ Background(charmtone.Anchovy),
35− },
36+ },
36− MissingLine: LineStyle{
37+ MissingLine: LineStyle{
37− LineNumber: lipgloss.NewStyle().
38+ LineNumber: lipgloss.NewStyle().
38− Background(charmtone.Ash),
39+ Background(charmtone.Ash),
39− Code: lipgloss.NewStyle().
40+ Code: lipgloss.NewStyle().
40− Background(charmtone.Ash),
41+ Background(charmtone.Ash),
41− },
42+ },
42− EqualLine: LineStyle{
43+ EqualLine: LineStyle{
43− LineNumber: lipgloss.NewStyle().
44+ LineNumber: lipgloss.NewStyle().
44− Foreground(charmtone.Charcoal).
45+ Foreground(charmtone.Charcoal).
45− Background(charmtone.Ash),
46+ Background(charmtone.Ash),
46− Code: lipgloss.NewStyle().
47+ Code: lipgloss.NewStyle().
47− Foreground(charmtone.Pepper).
48+ Foreground(charmtone.Pepper).
48− Background(charmtone.Salt),
49+ Background(charmtone.Salt),
49− },
50+ },
50− InsertLine: LineStyle{
51+ InsertLine: LineStyle{
51− LineNumber: lipgloss.NewStyle().
52+ LineNumber: lipgloss.NewStyle().
52− Foreground(charmtone.Turtle).
53+ Foreground(charmtone.Turtle).
53− Background(lipgloss.Color("#c8e6c9")),
54+ Background(lipgloss.Color("#c8e6c9")),
54− Symbol: lipgloss.NewStyle().
55+ Symbol: lipgloss.NewStyle().
55− Foreground(charmtone.Turtle).
56+ Foreground(charmtone.Turtle).
56− Background(lipgloss.Color("#e8f5e9")),
57+ Background(lipgloss.Color("#e8f5e9")),
57− Code: lipgloss.NewStyle().
58+ Code: lipgloss.NewStyle().
58− Foreground(charmtone.Pepper).
59+ Foreground(charmtone.Pepper).
59− Background(lipgloss.Color("#e8f5e9")),
60+ Background(lipgloss.Color("#e8f5e9")),
60− },
61+ },
61− DeleteLine: LineStyle{
62+ DeleteLine: LineStyle{
62− LineNumber: lipgloss.NewStyle().
63+ LineNumber: lipgloss.NewStyle().
63− Foreground(charmtone.Cherry).
64+ Foreground(charmtone.Cherry).
64− Background(lipgloss.Color("#ffcdd2")),
65+ Background(lipgloss.Color("#ffcdd2")),
65− Symbol: lipgloss.NewStyle().
66+ Symbol: lipgloss.NewStyle().
66− Foreground(charmtone.Cherry).
67+ Foreground(charmtone.Cherry).
67− Background(lipgloss.Color("#ffebee")),
68+ Background(lipgloss.Color("#ffebee")),
68− Code: lipgloss.NewStyle().
69+ Code: lipgloss.NewStyle().
69− Foreground(charmtone.Pepper).
70+ Foreground(charmtone.Pepper).
70− Background(lipgloss.Color("#ffebee")),
71+ Background(lipgloss.Color("#ffebee")),
72+ },
71− },
73+ }
72}
74}
73
75
74// DefaultDarkStyle provides a default dark theme style for the diff view.
76// DefaultDarkStyle provides a default dark theme style for the diff view.
75−var DefaultDarkStyle = Style{
77+func DefaultDarkStyle() Style {
78+ return Style{
76− DividerLine: LineStyle{
79+ DividerLine: LineStyle{
77− LineNumber: lipgloss.NewStyle().
80+ LineNumber: lipgloss.NewStyle().
78− Foreground(charmtone.Smoke).
81+ Foreground(charmtone.Smoke).
79− Background(charmtone.Sapphire),
82+ Background(charmtone.Sapphire),
80− Code: lipgloss.NewStyle().
83+ Code: lipgloss.NewStyle().
81− Foreground(charmtone.Smoke).
84+ Foreground(charmtone.Smoke).
82− Background(charmtone.Ox),
85+ Background(charmtone.Ox),
83− },
86+ },
84− MissingLine: LineStyle{
87+ MissingLine: LineStyle{
85− LineNumber: lipgloss.NewStyle().
88+ LineNumber: lipgloss.NewStyle().
86− Background(charmtone.Charcoal),
89+ Background(charmtone.Charcoal),
87− Code: lipgloss.NewStyle().
90+ Code: lipgloss.NewStyle().
88− Background(charmtone.Charcoal),
91+ Background(charmtone.Charcoal),
89− },
92+ },
90− EqualLine: LineStyle{
93+ EqualLine: LineStyle{
91− LineNumber: lipgloss.NewStyle().
94+ LineNumber: lipgloss.NewStyle().
92− Foreground(charmtone.Ash).
95+ Foreground(charmtone.Ash).
93− Background(charmtone.Charcoal),
96+ Background(charmtone.Charcoal),
94− Code: lipgloss.NewStyle().
97+ Code: lipgloss.NewStyle().
95− Foreground(charmtone.Salt).
98+ Foreground(charmtone.Salt).
96− Background(charmtone.Pepper),
99+ Background(charmtone.Pepper),
97− },
100+ },
98− InsertLine: LineStyle{
101+ InsertLine: LineStyle{
99− LineNumber: lipgloss.NewStyle().
102+ LineNumber: lipgloss.NewStyle().
100− Foreground(charmtone.Turtle).
103+ Foreground(charmtone.Turtle).
101− Background(lipgloss.Color("#293229")),
104+ Background(lipgloss.Color("#293229")),
102− Symbol: lipgloss.NewStyle().
105+ Symbol: lipgloss.NewStyle().
103− Foreground(charmtone.Turtle).
106+ Foreground(charmtone.Turtle).
104− Background(lipgloss.Color("#303a30")),
107+ Background(lipgloss.Color("#303a30")),
105− Code: lipgloss.NewStyle().
108+ Code: lipgloss.NewStyle().
106− Foreground(charmtone.Salt).
109+ Foreground(charmtone.Salt).
107− Background(lipgloss.Color("#303a30")),
110+ Background(lipgloss.Color("#303a30")),
108− },
111+ },
109− DeleteLine: LineStyle{
112+ DeleteLine: LineStyle{
110− LineNumber: lipgloss.NewStyle().
113+ LineNumber: lipgloss.NewStyle().
111− Foreground(charmtone.Cherry).
114+ Foreground(charmtone.Cherry).
112− Background(lipgloss.Color("#332929")),
115+ Background(lipgloss.Color("#332929")),
113− Symbol: lipgloss.NewStyle().
116+ Symbol: lipgloss.NewStyle().
114− Foreground(charmtone.Cherry).
117+ Foreground(charmtone.Cherry).
115− Background(lipgloss.Color("#3a3030")),
118+ Background(lipgloss.Color("#3a3030")),
116− Code: lipgloss.NewStyle().
119+ Code: lipgloss.NewStyle().
117− Foreground(charmtone.Salt).
120+ Foreground(charmtone.Salt).
118− Background(lipgloss.Color("#3a3030")),
121+ Background(lipgloss.Color("#3a3030")),
122+ },
119− },
123+ }
120}
124}