on main help sign in
chore: add dedicates diff styles
771835fKujtim Hoxha
internal/tui/components/chat/messages/renderer.go+23−12
@@ -600,45 +600,56 @@ func renderPlainContent(v *toolCallCmp, content string) string {
600 }
600 }
601 out = append(out, t.S().Muted.
601 out = append(out, t.S().Muted.
602 Width(width).
602 Width(width).
603− Background(t.BgSubtle).
603+ Background(t.BgBaseLighter).
604 Render(ln))
604 Render(ln))
605 }
605 }
606
606
607 if len(lines) > responseContextHeight {
607 if len(lines) > responseContextHeight {
608 out = append(out, t.S().Muted.
608 out = append(out, t.S().Muted.
609− Background(t.BgSubtle).
609+ Background(t.BgBaseLighter).
610 Width(width).
610 Width(width).
611 Render(fmt.Sprintf("... (%d lines)", len(lines)-responseContextHeight)))
611 Render(fmt.Sprintf("... (%d lines)", len(lines)-responseContextHeight)))
612 }
612 }
613 return strings.Join(out, "\n")
613 return strings.Join(out, "\n")
614}
614}
615
615
616+func pad(v any, width int) string {
617+ s := fmt.Sprintf("%v", v)
618+ w := ansi.StringWidth(s)
619+ if w >= width {
620+ return s
621+ }
622+ return strings.Repeat(" ", width-w) + s
623+}
624+
616func renderCodeContent(v *toolCallCmp, path, content string, offset int) string {
625func renderCodeContent(v *toolCallCmp, path, content string, offset int) string {
617 t := styles.CurrentTheme()
626 t := styles.CurrentTheme()
618 truncated := truncateHeight(content, responseContextHeight)
627 truncated := truncateHeight(content, responseContextHeight)
619
628
620− highlighted, _ := highlight.SyntaxHighlight(truncated, path, t.BgSubtle)
629+ highlighted, _ := highlight.SyntaxHighlight(truncated, path, t.BgBase)
621 lines := strings.Split(highlighted, "\n")
630 lines := strings.Split(highlighted, "\n")
622
631
623 if len(strings.Split(content, "\n")) > responseContextHeight {
632 if len(strings.Split(content, "\n")) > responseContextHeight {
624 lines = append(lines, t.S().Muted.
633 lines = append(lines, t.S().Muted.
625− Background(t.BgSubtle).
634+ Background(t.BgBase).
626− Width(v.textWidth()-2).
627− Render(fmt.Sprintf("... (%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
635+ Render(fmt.Sprintf(" ... (%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
628 }
636 }
629
637
638+ maxLineNumber := len(lines) + offset
639+ padding := lipgloss.Width(fmt.Sprintf("%d", maxLineNumber))
630 for i, ln := range lines {
640 for i, ln := range lines {
631− num := t.S().Muted.
641+ num := t.S().Base.
642+ Foreground(t.FgMuted).
632− Background(t.BgSubtle).
643+ Background(t.BgBase).
633− PaddingLeft(4).
634− PaddingRight(2).
644+ PaddingRight(1).
645+ PaddingLeft(1).
635− Render(fmt.Sprintf("%d", i+1+offset))
646+ Render(pad(i+1+offset, padding))
636 w := v.textWidth() - 2 - lipgloss.Width(num) // -2 for left padding
647 w := v.textWidth() - 2 - lipgloss.Width(num) // -2 for left padding
637 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
648 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
638 num,
649 num,
639 t.S().Base.
650 t.S().Base.
651+ PaddingLeft(1).
640 Width(w).
652 Width(w).
641− Background(t.BgSubtle).
642 Render(v.fit(ln, w)))
653 Render(v.fit(ln, w)))
643 }
654 }
644 return lipgloss.JoinVertical(lipgloss.Left, lines...)
655 return lipgloss.JoinVertical(lipgloss.Left, lines...)
internal/tui/components/core/helpers.go+2−1
@@ -148,8 +148,9 @@ func SelectableButtons(buttons []ButtonOpts, spacing string) string {
148}
148}
149
149
150func DiffFormatter() *diffview.DiffView {
150func DiffFormatter() *diffview.DiffView {
151+ t := styles.CurrentTheme()
151 formatDiff := diffview.New()
152 formatDiff := diffview.New()
152 style := chroma.MustNewStyle("crush", styles.GetChromaTheme())
153 style := chroma.MustNewStyle("crush", styles.GetChromaTheme())
153− diff := formatDiff.ChromaStyle(style)
154+ diff := formatDiff.ChromaStyle(style).Style(t.S().Diff)
154 return diff
155 return diff
155}
156}
internal/tui/styles/crush.go+4−3
@@ -14,9 +14,10 @@ func NewCrushTheme() *Theme {
14 Tertiary: charmtone.Bok,
14 Tertiary: charmtone.Bok,
15 Accent: charmtone.Zest,
15 Accent: charmtone.Zest,
16 // Backgrounds
16 // Backgrounds
17− BgBase: charmtone.Pepper,
17+ BgBase: charmtone.Pepper,
18+ BgBaseLighter: Lighten(charmtone.Pepper, 2),
18− BgSubtle: charmtone.Charcoal,
19+ BgSubtle: charmtone.Charcoal,
19− BgOverlay: charmtone.Iron,
20+ BgOverlay: charmtone.Iron,
20
21
21 // Foregrounds
22 // Foregrounds
22 FgBase: charmtone.Ash,
23 FgBase: charmtone.Ash,
internal/tui/styles/theme.go+49−34
@@ -10,6 +10,7 @@ import (
10 "github.com/charmbracelet/bubbles/v2/textarea"
10 "github.com/charmbracelet/bubbles/v2/textarea"
11 "github.com/charmbracelet/bubbles/v2/textinput"
11 "github.com/charmbracelet/bubbles/v2/textinput"
12 tea "github.com/charmbracelet/bubbletea/v2"
12 tea "github.com/charmbracelet/bubbletea/v2"
13+ "github.com/charmbracelet/crush/internal/exp/diffview"
13 "github.com/charmbracelet/glamour/v2/ansi"
14 "github.com/charmbracelet/glamour/v2/ansi"
14 "github.com/charmbracelet/lipgloss/v2"
15 "github.com/charmbracelet/lipgloss/v2"
15 "github.com/lucasb-eyer/go-colorful"
16 "github.com/lucasb-eyer/go-colorful"
@@ -31,9 +32,10 @@ type Theme struct {
31 Tertiary color.Color
32 Tertiary color.Color
32 Accent color.Color
33 Accent color.Color
33
34
35+ BgBase color.Color
34− BgBase color.Color
36+ BgBaseLighter color.Color
35− BgSubtle color.Color
37+ BgSubtle color.Color
36− BgOverlay color.Color
38+ BgOverlay color.Color
37
39
38 FgBase color.Color
40 FgBase color.Color
39 FgMuted color.Color
41 FgMuted color.Color
@@ -70,21 +72,6 @@ type Theme struct {
70 styles *Styles
72 styles *Styles
71}
73}
72
74
73−type Diff struct {
74− Added color.Color
75− Removed color.Color
76− Context color.Color
77− HunkHeader color.Color
78− HighlightAdded color.Color
79− HighlightRemoved color.Color
80− AddedBg color.Color
81− RemovedBg color.Color
82− ContextBg color.Color
83− LineNumber color.Color
84− AddedLineNumberBg color.Color
85− RemovedLineNumberBg color.Color
86−}
87−
88type Styles struct {
75type Styles struct {
89 Base lipgloss.Style
76 Base lipgloss.Style
90 SelectedBase lipgloss.Style
77 SelectedBase lipgloss.Style
@@ -112,7 +99,7 @@ type Styles struct {
112 Help help.Styles
99 Help help.Styles
113
100
114 // Diff
101 // Diff
115− Diff Diff
102+ Diff diffview.Style
116
103
117 // FilePicker
104 // FilePicker
118 FilePicker filepicker.Styles
105 FilePicker filepicker.Styles
@@ -421,22 +408,50 @@ func (t *Theme) buildStyles() *Styles {
421 FullSeparator: base.Foreground(t.Border),
408 FullSeparator: base.Foreground(t.Border),
422 },
409 },
423
410
424− // TODO: Fix this this is bad
411+ Diff: diffview.Style{
425− Diff: Diff{
412+ DividerLine: diffview.LineStyle{
426− Added: t.Green,
413+ LineNumber: lipgloss.NewStyle().
427− Removed: t.Red,
414+ Foreground(t.FgHalfMuted).
428− Context: t.FgSubtle,
415+ Background(t.BgBaseLighter),
429− HunkHeader: t.FgSubtle,
416+ Code: lipgloss.NewStyle().
430− HighlightAdded: t.GreenLight,
417+ Foreground(t.FgHalfMuted).
431− HighlightRemoved: t.RedLight,
418+ Background(t.BgBaseLighter),
432− AddedBg: t.GreenDark,
419+ },
433− RemovedBg: t.RedDark,
420+ MissingLine: diffview.LineStyle{
434− ContextBg: t.BgSubtle,
421+ LineNumber: lipgloss.NewStyle().
422+ Background(t.BgBaseLighter),
423+ Code: lipgloss.NewStyle().
424+ Background(t.BgBaseLighter),
425+ },
426+ EqualLine: diffview.LineStyle{
427+ LineNumber: lipgloss.NewStyle().
428+ Foreground(t.FgMuted).
429+ Background(t.BgBase),
430+ Code: lipgloss.NewStyle().
431+ Foreground(t.FgMuted).
432+ Background(t.BgBase),
433+ },
434+ InsertLine: diffview.LineStyle{
435+ LineNumber: lipgloss.NewStyle().
436+ Foreground(lipgloss.Color("#629657")).
437+ Background(lipgloss.Color("#2b322a")),
438+ Symbol: lipgloss.NewStyle().
439+ Foreground(lipgloss.Color("#629657")).
440+ Background(lipgloss.Color("#323931")),
441+ Code: lipgloss.NewStyle().
442+ Background(lipgloss.Color("#323931")),
443+ },
444+ DeleteLine: diffview.LineStyle{
435− LineNumber: t.FgMuted,
445+ LineNumber: lipgloss.NewStyle().
436− AddedLineNumberBg: t.GreenDark,
446+ Foreground(lipgloss.Color("#a45c59")).
437− RemovedLineNumberBg: t.RedDark,
447+ Background(lipgloss.Color("#312929")),
448+ Symbol: lipgloss.NewStyle().
449+ Foreground(lipgloss.Color("#a45c59")).
450+ Background(lipgloss.Color("#383030")),
451+ Code: lipgloss.NewStyle().
452+ Background(lipgloss.Color("#383030")),
453+ },
438 },
454 },
439−
440 FilePicker: filepicker.Styles{
455 FilePicker: filepicker.Styles{
441 DisabledCursor: base.Foreground(t.FgMuted),
456 DisabledCursor: base.Foreground(t.FgMuted),
442 Cursor: base.Foreground(t.FgBase),
457 Cursor: base.Foreground(t.FgBase),