@@ -1,8 +1,10 @@
11package styles
22
33import (
4+ "github.com/charmbracelet/glamour"
45 "github.com/charmbracelet/glamour/ansi"
56 "github.com/charmbracelet/lipgloss"
7+ "github.com/opencode-ai/opencode/internal/tui/theme"
68)
79
810const defaultMargin = 1
@@ -12,930 +14,271 @@ func boolPtr(b bool) *bool { return &b }
1214func stringPtr(s string) *string { return &s }
1315func uintPtr(u uint) *uint { return &u }
1416
15−// CatppuccinMarkdownStyle is the Catppuccin Mocha style for Glamour markdown rendering.
16−func CatppuccinMarkdownStyle() ansi.StyleConfig {
17− isDark := lipgloss.HasDarkBackground()
18− if isDark {
19− return catppuccinDark
20− }
21− return catppuccinLight
17+// returns a glamour TermRenderer configured with the current theme
18+func GetMarkdownRenderer(width int) *glamour.TermRenderer {
19+ r, _ := glamour.NewTermRenderer(
20+ glamour.WithStyles(generateMarkdownStyleConfig()),
21+ glamour.WithWordWrap(width),
22+ )
23+ return r
2224}
2325
24−var catppuccinDark = ansi.StyleConfig{
25− Document: ansi.StyleBlock{
26− StylePrimitive: ansi.StylePrimitive{
27− BlockPrefix: "\n",
28− BlockSuffix: "",
29− Color: stringPtr(dark.Text().Hex),
30− },
31− Margin: uintPtr(defaultMargin),
32− },
33− BlockQuote: ansi.StyleBlock{
34− StylePrimitive: ansi.StylePrimitive{
35− Color: stringPtr(dark.Yellow().Hex),
36− Italic: boolPtr(true),
37− Prefix: "┃ ",
38− },
39− Indent: uintPtr(1),
40− IndentToken: stringPtr(BaseStyle.Render(" ")),
41− },
42− List: ansi.StyleList{
43− LevelIndent: defaultMargin,
44− StyleBlock: ansi.StyleBlock{
45− IndentToken: stringPtr(BaseStyle.Render(" ")),
46− StylePrimitive: ansi.StylePrimitive{
47− Color: stringPtr(dark.Text().Hex),
48− },
49− },
50− },
51− Heading: ansi.StyleBlock{
52− StylePrimitive: ansi.StylePrimitive{
53− BlockSuffix: "\n",
54− Color: stringPtr(dark.Mauve().Hex),
55− Bold: boolPtr(true),
56− },
57− },
58− H1: ansi.StyleBlock{
59− StylePrimitive: ansi.StylePrimitive{
60− Prefix: "# ",
61− Color: stringPtr(dark.Lavender().Hex),
62− Bold: boolPtr(true),
63− BlockPrefix: "\n",
64− },
65− },
66− H2: ansi.StyleBlock{
67− StylePrimitive: ansi.StylePrimitive{
68− Prefix: "## ",
69− Color: stringPtr(dark.Mauve().Hex),
70− Bold: boolPtr(true),
71− },
72− },
73− H3: ansi.StyleBlock{
74− StylePrimitive: ansi.StylePrimitive{
75− Prefix: "### ",
76− Color: stringPtr(dark.Pink().Hex),
77− Bold: boolPtr(true),
78− },
79− },
80− H4: ansi.StyleBlock{
81− StylePrimitive: ansi.StylePrimitive{
82− Prefix: "#### ",
83− Color: stringPtr(dark.Flamingo().Hex),
84− Bold: boolPtr(true),
85− },
86− },
87− H5: ansi.StyleBlock{
88− StylePrimitive: ansi.StylePrimitive{
89− Prefix: "##### ",
90− Color: stringPtr(dark.Rosewater().Hex),
91− Bold: boolPtr(true),
92− },
93− },
94− H6: ansi.StyleBlock{
95− StylePrimitive: ansi.StylePrimitive{
96− Prefix: "###### ",
97− Color: stringPtr(dark.Rosewater().Hex),
98− Bold: boolPtr(true),
99− },
100− },
101− Strikethrough: ansi.StylePrimitive{
102− CrossedOut: boolPtr(true),
103− Color: stringPtr(dark.Overlay1().Hex),
104− },
105− Emph: ansi.StylePrimitive{
106− Color: stringPtr(dark.Yellow().Hex),
107− Italic: boolPtr(true),
108− },
109− Strong: ansi.StylePrimitive{
110− Bold: boolPtr(true),
111− Color: stringPtr(dark.Peach().Hex),
112− },
113− HorizontalRule: ansi.StylePrimitive{
114− Color: stringPtr(dark.Overlay0().Hex),
115− Format: "\n─────────────────────────────────────────\n",
116− },
117− Item: ansi.StylePrimitive{
118− BlockPrefix: "• ",
119− Color: stringPtr(dark.Blue().Hex),
120− },
121− Enumeration: ansi.StylePrimitive{
122− BlockPrefix: ". ",
123− Color: stringPtr(dark.Sky().Hex),
124− },
125− Task: ansi.StyleTask{
126− StylePrimitive: ansi.StylePrimitive{},
127− Ticked: "[✓] ",
128− Unticked: "[ ] ",
129− },
130− Link: ansi.StylePrimitive{
131− Color: stringPtr(dark.Sky().Hex),
132− Underline: boolPtr(true),
133− },
134− LinkText: ansi.StylePrimitive{
135− Color: stringPtr(dark.Pink().Hex),
136− Bold: boolPtr(true),
137− },
138− Image: ansi.StylePrimitive{
139− Color: stringPtr(dark.Sapphire().Hex),
140− Underline: boolPtr(true),
141− Format: "🖼 {{.text}}",
142− },
143− ImageText: ansi.StylePrimitive{
144− Color: stringPtr(dark.Pink().Hex),
145− Format: "{{.text}}",
146− },
147− Code: ansi.StyleBlock{
148− StylePrimitive: ansi.StylePrimitive{
149− Color: stringPtr(dark.Green().Hex),
150− Prefix: "",
151− Suffix: "",
152− },
153− },
154− CodeBlock: ansi.StyleCodeBlock{
155− StyleBlock: ansi.StyleBlock{
26+// creates an ansi.StyleConfig for markdown rendering
27+// using adaptive colors from the provided theme.
28+func generateMarkdownStyleConfig() ansi.StyleConfig {
29+ t := theme.CurrentTheme()
30+
31+ return ansi.StyleConfig{
32+ Document: ansi.StyleBlock{
15633 StylePrimitive: ansi.StylePrimitive{
157− Prefix: " ",
158− Color: stringPtr(dark.Text().Hex),
34+ BlockPrefix: "",
35+ BlockSuffix: "",
36+ Color: stringPtr(adaptiveColorToString(t.MarkdownText())),
15937 },
160−
16138 Margin: uintPtr(defaultMargin),
16239 },
163− Chroma: &ansi.Chroma{
164− Text: ansi.StylePrimitive{
165− Color: stringPtr(dark.Text().Hex),
166− },
167− Error: ansi.StylePrimitive{
168− Color: stringPtr(dark.Text().Hex),
169− },
170− Comment: ansi.StylePrimitive{
171− Color: stringPtr(dark.Overlay1().Hex),
172− },
173− CommentPreproc: ansi.StylePrimitive{
174− Color: stringPtr(dark.Pink().Hex),
175− },
176− Keyword: ansi.StylePrimitive{
177− Color: stringPtr(dark.Pink().Hex),
178− },
179− KeywordReserved: ansi.StylePrimitive{
180− Color: stringPtr(dark.Pink().Hex),
181− },
182− KeywordNamespace: ansi.StylePrimitive{
183− Color: stringPtr(dark.Pink().Hex),
184− },
185− KeywordType: ansi.StylePrimitive{
186− Color: stringPtr(dark.Sky().Hex),
187− },
188− Operator: ansi.StylePrimitive{
189− Color: stringPtr(dark.Pink().Hex),
190− },
191− Punctuation: ansi.StylePrimitive{
192− Color: stringPtr(dark.Text().Hex),
193− },
194− Name: ansi.StylePrimitive{
195− Color: stringPtr(dark.Sky().Hex),
196− },
197− NameBuiltin: ansi.StylePrimitive{
198− Color: stringPtr(dark.Sky().Hex),
199− },
200− NameTag: ansi.StylePrimitive{
201− Color: stringPtr(dark.Pink().Hex),
202− },
203− NameAttribute: ansi.StylePrimitive{
204− Color: stringPtr(dark.Green().Hex),
205− },
206− NameClass: ansi.StylePrimitive{
207− Color: stringPtr(dark.Sky().Hex),
208− },
209− NameConstant: ansi.StylePrimitive{
210− Color: stringPtr(dark.Mauve().Hex),
211− },
212− NameDecorator: ansi.StylePrimitive{
213− Color: stringPtr(dark.Green().Hex),
214− },
215− NameFunction: ansi.StylePrimitive{
216− Color: stringPtr(dark.Green().Hex),
217− },
218− LiteralNumber: ansi.StylePrimitive{
219− Color: stringPtr(dark.Teal().Hex),
220− },
221− LiteralString: ansi.StylePrimitive{
222− Color: stringPtr(dark.Yellow().Hex),
223− },
224− LiteralStringEscape: ansi.StylePrimitive{
225− Color: stringPtr(dark.Pink().Hex),
226− },
227− GenericDeleted: ansi.StylePrimitive{
228− Color: stringPtr(dark.Red().Hex),
229− },
230− GenericEmph: ansi.StylePrimitive{
231− Color: stringPtr(dark.Yellow().Hex),
40+ BlockQuote: ansi.StyleBlock{
41+ StylePrimitive: ansi.StylePrimitive{
42+ Color: stringPtr(adaptiveColorToString(t.MarkdownBlockQuote())),
23243 Italic: boolPtr(true),
44+ Prefix: "┃ ",
23345 },
234− GenericInserted: ansi.StylePrimitive{
235− Color: stringPtr(dark.Green().Hex),
236− },
237− GenericStrong: ansi.StylePrimitive{
238− Color: stringPtr(dark.Peach().Hex),
239− Bold: boolPtr(true),
240− },
241− GenericSubheading: ansi.StylePrimitive{
242− Color: stringPtr(dark.Mauve().Hex),
46+ Indent: uintPtr(1),
47+ IndentToken: stringPtr(BaseStyle().Render(" ")),
48+ },
49+ List: ansi.StyleList{
50+ LevelIndent: defaultMargin,
51+ StyleBlock: ansi.StyleBlock{
52+ IndentToken: stringPtr(BaseStyle().Render(" ")),
53+ StylePrimitive: ansi.StylePrimitive{
54+ Color: stringPtr(adaptiveColorToString(t.MarkdownText())),
55+ },
24356 },
24457 },
245− },
246− Table: ansi.StyleTable{
247− StyleBlock: ansi.StyleBlock{
58+ Heading: ansi.StyleBlock{
24859 StylePrimitive: ansi.StylePrimitive{
249− BlockPrefix: "\n",
25060 BlockSuffix: "\n",
61+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
62+ Bold: boolPtr(true),
25163 },
25264 },
253− CenterSeparator: stringPtr("┼"),
254− ColumnSeparator: stringPtr("│"),
255− RowSeparator: stringPtr("─"),
256− },
257− DefinitionDescription: ansi.StylePrimitive{
258− BlockPrefix: "\n ❯ ",
259− Color: stringPtr(dark.Sapphire().Hex),
260− },
261−}
262−
263−var catppuccinLight = ansi.StyleConfig{
264− Document: ansi.StyleBlock{
265− StylePrimitive: ansi.StylePrimitive{
266− BlockPrefix: "\n",
267− BlockSuffix: "\n",
268− Color: stringPtr(light.Text().Hex),
269− },
270− Margin: uintPtr(defaultMargin),
271− },
272− BlockQuote: ansi.StyleBlock{
273− StylePrimitive: ansi.StylePrimitive{
274− Color: stringPtr(light.Yellow().Hex),
275− Italic: boolPtr(true),
276− Prefix: "┃ ",
277− },
278− Indent: uintPtr(1),
279− Margin: uintPtr(defaultMargin),
280− },
281− List: ansi.StyleList{
282− LevelIndent: defaultMargin,
283− StyleBlock: ansi.StyleBlock{
65+ H1: ansi.StyleBlock{
28466 StylePrimitive: ansi.StylePrimitive{
285− Color: stringPtr(light.Text().Hex),
67+ Prefix: "# ",
68+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
69+ Bold: boolPtr(true),
28670 },
28771 },
288− },
289− Heading: ansi.StyleBlock{
290− StylePrimitive: ansi.StylePrimitive{
291− BlockSuffix: "\n",
292− Color: stringPtr(light.Mauve().Hex),
293− Bold: boolPtr(true),
294− },
295− },
296− H1: ansi.StyleBlock{
297− StylePrimitive: ansi.StylePrimitive{
298− Prefix: "# ",
299− Color: stringPtr(light.Lavender().Hex),
300− Bold: boolPtr(true),
301− BlockPrefix: "\n",
302− },
303− },
304− H2: ansi.StyleBlock{
305− StylePrimitive: ansi.StylePrimitive{
306− Prefix: "## ",
307− Color: stringPtr(light.Mauve().Hex),
308− Bold: boolPtr(true),
309− },
310− },
311− H3: ansi.StyleBlock{
312− StylePrimitive: ansi.StylePrimitive{
313− Prefix: "### ",
314− Color: stringPtr(light.Pink().Hex),
315− Bold: boolPtr(true),
316− },
317− },
318− H4: ansi.StyleBlock{
319− StylePrimitive: ansi.StylePrimitive{
320− Prefix: "#### ",
321− Color: stringPtr(light.Flamingo().Hex),
322− Bold: boolPtr(true),
323− },
324− },
325− H5: ansi.StyleBlock{
326− StylePrimitive: ansi.StylePrimitive{
327− Prefix: "##### ",
328− Color: stringPtr(light.Rosewater().Hex),
329− Bold: boolPtr(true),
330− },
331− },
332− H6: ansi.StyleBlock{
333− StylePrimitive: ansi.StylePrimitive{
334− Prefix: "###### ",
335− Color: stringPtr(light.Rosewater().Hex),
336− Bold: boolPtr(true),
337− },
338− },
339− Strikethrough: ansi.StylePrimitive{
340− CrossedOut: boolPtr(true),
341− Color: stringPtr(light.Overlay1().Hex),
342− },
343− Emph: ansi.StylePrimitive{
344− Color: stringPtr(light.Yellow().Hex),
345− Italic: boolPtr(true),
346− },
347− Strong: ansi.StylePrimitive{
348− Bold: boolPtr(true),
349− Color: stringPtr(light.Peach().Hex),
350− },
351− HorizontalRule: ansi.StylePrimitive{
352− Color: stringPtr(light.Overlay0().Hex),
353− Format: "\n─────────────────────────────────────────\n",
354− },
355− Item: ansi.StylePrimitive{
356− BlockPrefix: "• ",
357− Color: stringPtr(light.Blue().Hex),
358− },
359− Enumeration: ansi.StylePrimitive{
360− BlockPrefix: ". ",
361− Color: stringPtr(light.Sky().Hex),
362− },
363− Task: ansi.StyleTask{
364− StylePrimitive: ansi.StylePrimitive{},
365− Ticked: "[✓] ",
366− Unticked: "[ ] ",
367− },
368− Link: ansi.StylePrimitive{
369− Color: stringPtr(light.Sky().Hex),
370− Underline: boolPtr(true),
371− },
372− LinkText: ansi.StylePrimitive{
373− Color: stringPtr(light.Pink().Hex),
374− Bold: boolPtr(true),
375− },
376− Image: ansi.StylePrimitive{
377− Color: stringPtr(light.Sapphire().Hex),
378− Underline: boolPtr(true),
379− Format: "🖼 {{.text}}",
380− },
381− ImageText: ansi.StylePrimitive{
382− Color: stringPtr(light.Pink().Hex),
383− Format: "{{.text}}",
384− },
385− Code: ansi.StyleBlock{
386− StylePrimitive: ansi.StylePrimitive{
387− Color: stringPtr(light.Green().Hex),
388− Prefix: " ",
389− Suffix: " ",
390− },
391− },
392− CodeBlock: ansi.StyleCodeBlock{
393− StyleBlock: ansi.StyleBlock{
72+ H2: ansi.StyleBlock{
39473 StylePrimitive: ansi.StylePrimitive{
395− Prefix: " ",
396− Color: stringPtr(light.Text().Hex),
74+ Prefix: "## ",
75+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
76+ Bold: boolPtr(true),
39777 },
398−
399− Margin: uintPtr(defaultMargin),
40078 },
401− Chroma: &ansi.Chroma{
402− Text: ansi.StylePrimitive{
403− Color: stringPtr(light.Text().Hex),
404− },
405− Error: ansi.StylePrimitive{
406− Color: stringPtr(light.Text().Hex),
407− },
408− Comment: ansi.StylePrimitive{
409− Color: stringPtr(light.Overlay1().Hex),
410− },
411− CommentPreproc: ansi.StylePrimitive{
412− Color: stringPtr(light.Pink().Hex),
413− },
414− Keyword: ansi.StylePrimitive{
415− Color: stringPtr(light.Pink().Hex),
416− },
417− KeywordReserved: ansi.StylePrimitive{
418− Color: stringPtr(light.Pink().Hex),
419− },
420− KeywordNamespace: ansi.StylePrimitive{
421− Color: stringPtr(light.Pink().Hex),
422− },
423− KeywordType: ansi.StylePrimitive{
424− Color: stringPtr(light.Sky().Hex),
425− },
426− Operator: ansi.StylePrimitive{
427− Color: stringPtr(light.Pink().Hex),
428− },
429− Punctuation: ansi.StylePrimitive{
430− Color: stringPtr(light.Text().Hex),
431− },
432− Name: ansi.StylePrimitive{
433− Color: stringPtr(light.Sky().Hex),
434− },
435− NameBuiltin: ansi.StylePrimitive{
436− Color: stringPtr(light.Sky().Hex),
437− },
438− NameTag: ansi.StylePrimitive{
439− Color: stringPtr(light.Pink().Hex),
440− },
441− NameAttribute: ansi.StylePrimitive{
442− Color: stringPtr(light.Green().Hex),
443− },
444− NameClass: ansi.StylePrimitive{
445− Color: stringPtr(light.Sky().Hex),
446− },
447− NameConstant: ansi.StylePrimitive{
448− Color: stringPtr(light.Mauve().Hex),
449− },
450− NameDecorator: ansi.StylePrimitive{
451− Color: stringPtr(light.Green().Hex),
452− },
453− NameFunction: ansi.StylePrimitive{
454− Color: stringPtr(light.Green().Hex),
455− },
456− LiteralNumber: ansi.StylePrimitive{
457− Color: stringPtr(light.Teal().Hex),
458− },
459− LiteralString: ansi.StylePrimitive{
460− Color: stringPtr(light.Yellow().Hex),
461− },
462− LiteralStringEscape: ansi.StylePrimitive{
463− Color: stringPtr(light.Pink().Hex),
464− },
465− GenericDeleted: ansi.StylePrimitive{
466− Color: stringPtr(light.Red().Hex),
467− },
468− GenericEmph: ansi.StylePrimitive{
469− Color: stringPtr(light.Yellow().Hex),
470− Italic: boolPtr(true),
471− },
472− GenericInserted: ansi.StylePrimitive{
473− Color: stringPtr(light.Green().Hex),
474− },
475− GenericStrong: ansi.StylePrimitive{
476− Color: stringPtr(light.Peach().Hex),
477− Bold: boolPtr(true),
478− },
479− GenericSubheading: ansi.StylePrimitive{
480− Color: stringPtr(light.Mauve().Hex),
481− },
482− },
483− },
484− Table: ansi.StyleTable{
485− StyleBlock: ansi.StyleBlock{
79+ H3: ansi.StyleBlock{
48680 StylePrimitive: ansi.StylePrimitive{
487− BlockPrefix: "\n",
488− BlockSuffix: "\n",
81+ Prefix: "### ",
82+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
83+ Bold: boolPtr(true),
48984 },
49085 },
491− CenterSeparator: stringPtr("┼"),
492− ColumnSeparator: stringPtr("│"),
493− RowSeparator: stringPtr("─"),
494− },
495− DefinitionDescription: ansi.StylePrimitive{
496− BlockPrefix: "\n ❯ ",
497− Color: stringPtr(light.Sapphire().Hex),
498− },
499−}
500−
501−func MarkdownTheme(focused bool) ansi.StyleConfig {
502− if !focused {
503− return ASCIIStyleConfig
504− } else {
505− return DraculaStyleConfig
506− }
507−}
508−
509−const (
510− defaultListIndent = 2
511− defaultListLevelIndent = 4
512−)
513−
514−var ASCIIStyleConfig = ansi.StyleConfig{
515− Document: ansi.StyleBlock{
516− StylePrimitive: ansi.StylePrimitive{
517− BackgroundColor: stringPtr(Background.Dark),
518− Color: stringPtr(ForgroundDim.Dark),
519− },
520− Indent: uintPtr(1),
521− IndentToken: stringPtr(BaseStyle.Render(" ")),
522− },
523− BlockQuote: ansi.StyleBlock{
524− StylePrimitive: ansi.StylePrimitive{
525− BackgroundColor: stringPtr(Background.Dark),
526− },
527− Indent: uintPtr(1),
528− IndentToken: stringPtr("| "),
529− },
530− Paragraph: ansi.StyleBlock{
531− StylePrimitive: ansi.StylePrimitive{
532− BackgroundColor: stringPtr(Background.Dark),
533− },
534− },
535− List: ansi.StyleList{
536− StyleBlock: ansi.StyleBlock{
537− IndentToken: stringPtr(BaseStyle.Render(" ")),
86+ H4: ansi.StyleBlock{
53887 StylePrimitive: ansi.StylePrimitive{
539− BackgroundColor: stringPtr(Background.Dark),
88+ Prefix: "#### ",
89+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
90+ Bold: boolPtr(true),
54091 },
54192 },
542− LevelIndent: defaultListLevelIndent,
543− },
544− Heading: ansi.StyleBlock{
545− StylePrimitive: ansi.StylePrimitive{
546− BackgroundColor: stringPtr(Background.Dark),
547− BlockSuffix: "\n",
548− },
549− },
550− H1: ansi.StyleBlock{
551− StylePrimitive: ansi.StylePrimitive{
552− BackgroundColor: stringPtr(Background.Dark),
553− Prefix: "# ",
554− },
555− },
556− H2: ansi.StyleBlock{
557− StylePrimitive: ansi.StylePrimitive{
558− BackgroundColor: stringPtr(Background.Dark),
559− Prefix: "## ",
560− },
561− },
562− H3: ansi.StyleBlock{
563− StylePrimitive: ansi.StylePrimitive{
564− BackgroundColor: stringPtr(Background.Dark),
565− Prefix: "### ",
566− },
567− },
568− H4: ansi.StyleBlock{
569− StylePrimitive: ansi.StylePrimitive{
570− BackgroundColor: stringPtr(Background.Dark),
571− Prefix: "#### ",
572− },
573− },
574− H5: ansi.StyleBlock{
575− StylePrimitive: ansi.StylePrimitive{
576− BackgroundColor: stringPtr(Background.Dark),
577− Prefix: "##### ",
578− },
579− },
580− H6: ansi.StyleBlock{
581− StylePrimitive: ansi.StylePrimitive{
582− BackgroundColor: stringPtr(Background.Dark),
583− Prefix: "###### ",
584− },
585− },
586− Strikethrough: ansi.StylePrimitive{
587− BackgroundColor: stringPtr(Background.Dark),
588− BlockPrefix: "~~",
589− BlockSuffix: "~~",
590− },
591− Emph: ansi.StylePrimitive{
592− BackgroundColor: stringPtr(Background.Dark),
593− BlockPrefix: "*",
594− BlockSuffix: "*",
595− },
596− Strong: ansi.StylePrimitive{
597− BackgroundColor: stringPtr(Background.Dark),
598− BlockPrefix: "**",
599− BlockSuffix: "**",
600− },
601− HorizontalRule: ansi.StylePrimitive{
602− BackgroundColor: stringPtr(Background.Dark),
603− Format: "\n--------\n",
604− },
605− Item: ansi.StylePrimitive{
606− BlockPrefix: "• ",
607− BackgroundColor: stringPtr(Background.Dark),
608− },
609− Enumeration: ansi.StylePrimitive{
610− BlockPrefix: ". ",
611− BackgroundColor: stringPtr(Background.Dark),
612− },
613− Task: ansi.StyleTask{
614− Ticked: "[x] ",
615− Unticked: "[ ] ",
616− StylePrimitive: ansi.StylePrimitive{
617− BackgroundColor: stringPtr(Background.Dark),
618− },
619− },
620− ImageText: ansi.StylePrimitive{
621− BackgroundColor: stringPtr(Background.Dark),
622− Format: "Image: {{.text}} →",
623− },
624− Code: ansi.StyleBlock{
625− StylePrimitive: ansi.StylePrimitive{
626− BlockPrefix: "`",
627− BlockSuffix: "`",
628− BackgroundColor: stringPtr(Background.Dark),
629− },
630− },
631− CodeBlock: ansi.StyleCodeBlock{
632− StyleBlock: ansi.StyleBlock{
93+ H5: ansi.StyleBlock{
63394 StylePrimitive: ansi.StylePrimitive{
634− BackgroundColor: stringPtr(Background.Dark),
95+ Prefix: "##### ",
96+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
97+ Bold: boolPtr(true),
63598 },
636− Margin: uintPtr(defaultMargin),
63799 },
638− },
639− Table: ansi.StyleTable{
640− StyleBlock: ansi.StyleBlock{
100+ H6: ansi.StyleBlock{
641101 StylePrimitive: ansi.StylePrimitive{
642− BackgroundColor: stringPtr(Background.Dark),
102+ Prefix: "###### ",
103+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
104+ Bold: boolPtr(true),
643105 },
644− IndentToken: stringPtr(BaseStyle.Render(" ")),
645− },
646− CenterSeparator: stringPtr("|"),
647− ColumnSeparator: stringPtr("|"),
648− RowSeparator: stringPtr("-"),
649− },
650− DefinitionDescription: ansi.StylePrimitive{
651− BackgroundColor: stringPtr(Background.Dark),
652− BlockPrefix: "\n* ",
653− },
654−}
655−
656−var DraculaStyleConfig = ansi.StyleConfig{
657− Document: ansi.StyleBlock{
658− StylePrimitive: ansi.StylePrimitive{
659− Color: stringPtr(Forground.Dark),
660− BackgroundColor: stringPtr(Background.Dark),
661− },
662− Indent: uintPtr(defaultMargin),
663− IndentToken: stringPtr(BaseStyle.Render(" ")),
664− },
665− BlockQuote: ansi.StyleBlock{
666− StylePrimitive: ansi.StylePrimitive{
667− Color: stringPtr("#f1fa8c"),
668− Italic: boolPtr(true),
669− BackgroundColor: stringPtr(Background.Dark),
670106 },
671− Indent: uintPtr(defaultMargin),
672− IndentToken: stringPtr(BaseStyle.Render(" ")),
673− },
674− Paragraph: ansi.StyleBlock{
675− StylePrimitive: ansi.StylePrimitive{
676− BackgroundColor: stringPtr(Background.Dark),
107+ Strikethrough: ansi.StylePrimitive{
108+ CrossedOut: boolPtr(true),
109+ Color: stringPtr(adaptiveColorToString(t.TextMuted())),
677110 },
678− },
679− List: ansi.StyleList{
680− LevelIndent: defaultMargin,
681− StyleBlock: ansi.StyleBlock{
682− IndentToken: stringPtr(BaseStyle.Render(" ")),
683− StylePrimitive: ansi.StylePrimitive{
684− Color: stringPtr(Forground.Dark),
685− BackgroundColor: stringPtr(Background.Dark),
686− },
111+ Emph: ansi.StylePrimitive{
112+ Color: stringPtr(adaptiveColorToString(t.MarkdownEmph())),
113+ Italic: boolPtr(true),
687114 },
688− },
689− Heading: ansi.StyleBlock{
690− StylePrimitive: ansi.StylePrimitive{
691− BlockSuffix: "\n",
692− Color: stringPtr(PrimaryColor.Dark),
693− Bold: boolPtr(true),
694− BackgroundColor: stringPtr(Background.Dark),
115+ Strong: ansi.StylePrimitive{
116+ Bold: boolPtr(true),
117+ Color: stringPtr(adaptiveColorToString(t.MarkdownStrong())),
695118 },
696− },
697− H1: ansi.StyleBlock{
698− StylePrimitive: ansi.StylePrimitive{
699− Prefix: "# ",
700− BackgroundColor: stringPtr(Background.Dark),
119+ HorizontalRule: ansi.StylePrimitive{
120+ Color: stringPtr(adaptiveColorToString(t.MarkdownHorizontalRule())),
121+ Format: "\n─────────────────────────────────────────\n",
701122 },
702− },
703− H2: ansi.StyleBlock{
704− StylePrimitive: ansi.StylePrimitive{
705− Prefix: "## ",
706− BackgroundColor: stringPtr(Background.Dark),
123+ Item: ansi.StylePrimitive{
124+ BlockPrefix: "• ",
125+ Color: stringPtr(adaptiveColorToString(t.MarkdownListItem())),
707126 },
708− },
709− H3: ansi.StyleBlock{
710− StylePrimitive: ansi.StylePrimitive{
711− Prefix: "### ",
712− BackgroundColor: stringPtr(Background.Dark),
127+ Enumeration: ansi.StylePrimitive{
128+ BlockPrefix: ". ",
129+ Color: stringPtr(adaptiveColorToString(t.MarkdownListEnumeration())),
713130 },
714− },
715− H4: ansi.StyleBlock{
716− StylePrimitive: ansi.StylePrimitive{
717− Prefix: "#### ",
718− BackgroundColor: stringPtr(Background.Dark),
131+ Task: ansi.StyleTask{
132+ StylePrimitive: ansi.StylePrimitive{},
133+ Ticked: "[✓] ",
134+ Unticked: "[ ] ",
719135 },
720− },
721− H5: ansi.StyleBlock{
722− StylePrimitive: ansi.StylePrimitive{
723− Prefix: "##### ",
724− BackgroundColor: stringPtr(Background.Dark),
136+ Link: ansi.StylePrimitive{
137+ Color: stringPtr(adaptiveColorToString(t.MarkdownLink())),
138+ Underline: boolPtr(true),
725139 },
726− },
727− H6: ansi.StyleBlock{
728− StylePrimitive: ansi.StylePrimitive{
729− Prefix: "###### ",
730− BackgroundColor: stringPtr(Background.Dark),
140+ LinkText: ansi.StylePrimitive{
141+ Color: stringPtr(adaptiveColorToString(t.MarkdownLinkText())),
142+ Bold: boolPtr(true),
731143 },
732− },
733− Strikethrough: ansi.StylePrimitive{
734− CrossedOut: boolPtr(true),
735− BackgroundColor: stringPtr(Background.Dark),
736− },
737− Emph: ansi.StylePrimitive{
738− Color: stringPtr("#f1fa8c"),
739− Italic: boolPtr(true),
740− BackgroundColor: stringPtr(Background.Dark),
741− },
742− Strong: ansi.StylePrimitive{
743− Bold: boolPtr(true),
744− Color: stringPtr(Blue.Dark),
745− BackgroundColor: stringPtr(Background.Dark),
746− },
747− HorizontalRule: ansi.StylePrimitive{
748− Color: stringPtr("#6272A4"),
749− Format: "\n--------\n",
750− BackgroundColor: stringPtr(Background.Dark),
751− },
752− Item: ansi.StylePrimitive{
753− BlockPrefix: "• ",
754− BackgroundColor: stringPtr(Background.Dark),
755− },
756− Enumeration: ansi.StylePrimitive{
757− BlockPrefix: ". ",
758− Color: stringPtr("#8be9fd"),
759− BackgroundColor: stringPtr(Background.Dark),
760− },
761− Task: ansi.StyleTask{
762− StylePrimitive: ansi.StylePrimitive{
763− BackgroundColor: stringPtr(Background.Dark),
144+ Image: ansi.StylePrimitive{
145+ Color: stringPtr(adaptiveColorToString(t.MarkdownImage())),
146+ Underline: boolPtr(true),
147+ Format: "🖼 {{.text}}",
764148 },
765− Ticked: "[✓] ",
766− Unticked: "[ ] ",
767− },
768− Link: ansi.StylePrimitive{
769− Color: stringPtr("#8be9fd"),
770− Underline: boolPtr(true),
771− BackgroundColor: stringPtr(Background.Dark),
772− },
773− LinkText: ansi.StylePrimitive{
774− Color: stringPtr("#ff79c6"),
775− BackgroundColor: stringPtr(Background.Dark),
776− },
777− Image: ansi.StylePrimitive{
778− Color: stringPtr("#8be9fd"),
779− Underline: boolPtr(true),
780− BackgroundColor: stringPtr(Background.Dark),
781− },
782− ImageText: ansi.StylePrimitive{
783− Color: stringPtr("#ff79c6"),
784− Format: "Image: {{.text}} →",
785− BackgroundColor: stringPtr(Background.Dark),
786− },
787− Code: ansi.StyleBlock{
788− StylePrimitive: ansi.StylePrimitive{
789− Color: stringPtr("#50fa7b"),
790− BackgroundColor: stringPtr(Background.Dark),
149+ ImageText: ansi.StylePrimitive{
150+ Color: stringPtr(adaptiveColorToString(t.MarkdownImageText())),
151+ Format: "{{.text}}",
791152 },
792− },
793− Text: ansi.StylePrimitive{
794− BackgroundColor: stringPtr(Background.Dark),
795− },
796− DefinitionList: ansi.StyleBlock{},
797− CodeBlock: ansi.StyleCodeBlock{
798− StyleBlock: ansi.StyleBlock{
153+ Code: ansi.StyleBlock{
799154 StylePrimitive: ansi.StylePrimitive{
800− Color: stringPtr(Blue.Dark),
801− BackgroundColor: stringPtr(Background.Dark),
802− },
803− Margin: uintPtr(defaultMargin),
804− },
805− Chroma: &ansi.Chroma{
806− NameOther: ansi.StylePrimitive{
807− BackgroundColor: stringPtr(Background.Dark),
808− },
809− Literal: ansi.StylePrimitive{
810− BackgroundColor: stringPtr(Background.Dark),
811− },
812− NameException: ansi.StylePrimitive{
813− BackgroundColor: stringPtr(Background.Dark),
814− },
815− LiteralDate: ansi.StylePrimitive{
816− BackgroundColor: stringPtr(Background.Dark),
817− },
818− Text: ansi.StylePrimitive{
819− Color: stringPtr(Forground.Dark),
820− BackgroundColor: stringPtr(Background.Dark),
821− },
822− Error: ansi.StylePrimitive{
823− Color: stringPtr("#f8f8f2"),
824− BackgroundColor: stringPtr("#ff5555"),
825− },
826− Comment: ansi.StylePrimitive{
827− Color: stringPtr("#6272A4"),
828− BackgroundColor: stringPtr(Background.Dark),
829− },
830− CommentPreproc: ansi.StylePrimitive{
831− Color: stringPtr("#ff79c6"),
832− BackgroundColor: stringPtr(Background.Dark),
833− },
834− Keyword: ansi.StylePrimitive{
835− Color: stringPtr("#ff79c6"),
836− BackgroundColor: stringPtr(Background.Dark),
837− },
838− KeywordReserved: ansi.StylePrimitive{
839− Color: stringPtr("#ff79c6"),
840− BackgroundColor: stringPtr(Background.Dark),
841− },
842− KeywordNamespace: ansi.StylePrimitive{
843− Color: stringPtr("#ff79c6"),
844− BackgroundColor: stringPtr(Background.Dark),
845− },
846− KeywordType: ansi.StylePrimitive{
847− Color: stringPtr("#8be9fd"),
848− BackgroundColor: stringPtr(Background.Dark),
849− },
850− Operator: ansi.StylePrimitive{
851− Color: stringPtr("#ff79c6"),
852− BackgroundColor: stringPtr(Background.Dark),
853− },
854− Punctuation: ansi.StylePrimitive{
855− Color: stringPtr(Forground.Dark),
856− BackgroundColor: stringPtr(Background.Dark),
857− },
858− Name: ansi.StylePrimitive{
859− Color: stringPtr("#8be9fd"),
860− BackgroundColor: stringPtr(Background.Dark),
861− },
862− NameBuiltin: ansi.StylePrimitive{
863− Color: stringPtr("#8be9fd"),
864− BackgroundColor: stringPtr(Background.Dark),
865− },
866− NameTag: ansi.StylePrimitive{
867− Color: stringPtr("#ff79c6"),
868− BackgroundColor: stringPtr(Background.Dark),
869− },
870− NameAttribute: ansi.StylePrimitive{
871− Color: stringPtr("#50fa7b"),
872− BackgroundColor: stringPtr(Background.Dark),
873− },
874− NameClass: ansi.StylePrimitive{
875− Color: stringPtr("#8be9fd"),
876− BackgroundColor: stringPtr(Background.Dark),
877− },
878− NameConstant: ansi.StylePrimitive{
879− Color: stringPtr("#bd93f9"),
880− BackgroundColor: stringPtr(Background.Dark),
881− },
882− NameDecorator: ansi.StylePrimitive{
883− Color: stringPtr("#50fa7b"),
884− BackgroundColor: stringPtr(Background.Dark),
885− },
886− NameFunction: ansi.StylePrimitive{
887− Color: stringPtr("#50fa7b"),
888− BackgroundColor: stringPtr(Background.Dark),
889− },
890− LiteralNumber: ansi.StylePrimitive{
891− Color: stringPtr("#6EEFC0"),
892− BackgroundColor: stringPtr(Background.Dark),
893− },
894− LiteralString: ansi.StylePrimitive{
895− Color: stringPtr("#f1fa8c"),
896− BackgroundColor: stringPtr(Background.Dark),
897− },
898− LiteralStringEscape: ansi.StylePrimitive{
899− Color: stringPtr("#ff79c6"),
900− BackgroundColor: stringPtr(Background.Dark),
901− },
902− GenericDeleted: ansi.StylePrimitive{
903− Color: stringPtr("#ff5555"),
904− BackgroundColor: stringPtr(Background.Dark),
905− },
906− GenericEmph: ansi.StylePrimitive{
907− Color: stringPtr("#f1fa8c"),
908− Italic: boolPtr(true),
909− BackgroundColor: stringPtr(Background.Dark),
910− },
911− GenericInserted: ansi.StylePrimitive{
912− Color: stringPtr("#50fa7b"),
913− BackgroundColor: stringPtr(Background.Dark),
914− },
915− GenericStrong: ansi.StylePrimitive{
916− Color: stringPtr("#ffb86c"),
917− Bold: boolPtr(true),
918− BackgroundColor: stringPtr(Background.Dark),
919− },
920− GenericSubheading: ansi.StylePrimitive{
921− Color: stringPtr("#bd93f9"),
922− BackgroundColor: stringPtr(Background.Dark),
923− },
924− Background: ansi.StylePrimitive{
925− BackgroundColor: stringPtr(Background.Dark),
926− },
927− },
928− },
929− Table: ansi.StyleTable{
930− StyleBlock: ansi.StyleBlock{
155+ Color: stringPtr(adaptiveColorToString(t.MarkdownCode())),
156+ Prefix: "",
157+ Suffix: "",
158+ },
159+ },
160+ CodeBlock: ansi.StyleCodeBlock{
161+ StyleBlock: ansi.StyleBlock{
162+ StylePrimitive: ansi.StylePrimitive{
163+ Prefix: " ",
164+ Color: stringPtr(adaptiveColorToString(t.MarkdownCodeBlock())),
165+ },
166+ Margin: uintPtr(defaultMargin),
167+ },
168+ Chroma: &ansi.Chroma{
169+ Text: ansi.StylePrimitive{
170+ Color: stringPtr(adaptiveColorToString(t.MarkdownText())),
171+ },
172+ Error: ansi.StylePrimitive{
173+ Color: stringPtr(adaptiveColorToString(t.Error())),
174+ },
175+ Comment: ansi.StylePrimitive{
176+ Color: stringPtr(adaptiveColorToString(t.SyntaxComment())),
177+ },
178+ CommentPreproc: ansi.StylePrimitive{
179+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
180+ },
181+ Keyword: ansi.StylePrimitive{
182+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
183+ },
184+ KeywordReserved: ansi.StylePrimitive{
185+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
186+ },
187+ KeywordNamespace: ansi.StylePrimitive{
188+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
189+ },
190+ KeywordType: ansi.StylePrimitive{
191+ Color: stringPtr(adaptiveColorToString(t.SyntaxType())),
192+ },
193+ Operator: ansi.StylePrimitive{
194+ Color: stringPtr(adaptiveColorToString(t.SyntaxOperator())),
195+ },
196+ Punctuation: ansi.StylePrimitive{
197+ Color: stringPtr(adaptiveColorToString(t.SyntaxPunctuation())),
198+ },
199+ Name: ansi.StylePrimitive{
200+ Color: stringPtr(adaptiveColorToString(t.SyntaxVariable())),
201+ },
202+ NameBuiltin: ansi.StylePrimitive{
203+ Color: stringPtr(adaptiveColorToString(t.SyntaxVariable())),
204+ },
205+ NameTag: ansi.StylePrimitive{
206+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
207+ },
208+ NameAttribute: ansi.StylePrimitive{
209+ Color: stringPtr(adaptiveColorToString(t.SyntaxFunction())),
210+ },
211+ NameClass: ansi.StylePrimitive{
212+ Color: stringPtr(adaptiveColorToString(t.SyntaxType())),
213+ },
214+ NameConstant: ansi.StylePrimitive{
215+ Color: stringPtr(adaptiveColorToString(t.SyntaxVariable())),
216+ },
217+ NameDecorator: ansi.StylePrimitive{
218+ Color: stringPtr(adaptiveColorToString(t.SyntaxFunction())),
219+ },
220+ NameFunction: ansi.StylePrimitive{
221+ Color: stringPtr(adaptiveColorToString(t.SyntaxFunction())),
222+ },
223+ LiteralNumber: ansi.StylePrimitive{
224+ Color: stringPtr(adaptiveColorToString(t.SyntaxNumber())),
225+ },
226+ LiteralString: ansi.StylePrimitive{
227+ Color: stringPtr(adaptiveColorToString(t.SyntaxString())),
228+ },
229+ LiteralStringEscape: ansi.StylePrimitive{
230+ Color: stringPtr(adaptiveColorToString(t.SyntaxKeyword())),
231+ },
232+ GenericDeleted: ansi.StylePrimitive{
233+ Color: stringPtr(adaptiveColorToString(t.DiffRemoved())),
234+ },
235+ GenericEmph: ansi.StylePrimitive{
236+ Color: stringPtr(adaptiveColorToString(t.MarkdownEmph())),
237+ Italic: boolPtr(true),
238+ },
239+ GenericInserted: ansi.StylePrimitive{
240+ Color: stringPtr(adaptiveColorToString(t.DiffAdded())),
241+ },
242+ GenericStrong: ansi.StylePrimitive{
243+ Color: stringPtr(adaptiveColorToString(t.MarkdownStrong())),
244+ Bold: boolPtr(true),
245+ },
246+ GenericSubheading: ansi.StylePrimitive{
247+ Color: stringPtr(adaptiveColorToString(t.MarkdownHeading())),
248+ },
249+ },
250+ },
251+ Table: ansi.StyleTable{
252+ StyleBlock: ansi.StyleBlock{
253+ StylePrimitive: ansi.StylePrimitive{
254+ BlockPrefix: "\n",
255+ BlockSuffix: "\n",
256+ },
257+ },
258+ CenterSeparator: stringPtr("┼"),
259+ ColumnSeparator: stringPtr("│"),
260+ RowSeparator: stringPtr("─"),
261+ },
262+ DefinitionDescription: ansi.StylePrimitive{
263+ BlockPrefix: "\n ❯ ",
264+ Color: stringPtr(adaptiveColorToString(t.MarkdownLinkText())),
265+ },
266+ Text: ansi.StylePrimitive{
267+ Color: stringPtr(adaptiveColorToString(t.MarkdownText())),
268+ },
269+ Paragraph: ansi.StyleBlock{
931270 StylePrimitive: ansi.StylePrimitive{
932− BackgroundColor: stringPtr(Background.Dark),
271+ Color: stringPtr(adaptiveColorToString(t.MarkdownText())),
933272 },
934− IndentToken: stringPtr(BaseStyle.Render(" ")),
935273 },
936− },
937− DefinitionDescription: ansi.StylePrimitive{
938− BlockPrefix: "\n* ",
939− BackgroundColor: stringPtr(Background.Dark),
940− },
274+ }
275+}
276+
277+// adaptiveColorToString converts a lipgloss.AdaptiveColor to the appropriate
278+// hex color string based on the current terminal background
279+func adaptiveColorToString(color lipgloss.AdaptiveColor) string {
280+ if lipgloss.HasDarkBackground() {
281+ return color.Dark
282+ }
283+ return color.Light
941284}