on main help sign in
chore: add dedicates diff styles
commit771835fdf128e49f93f6039c622ec72824ddeeb9 authorKujtim Hoxha <kujtimii.h@gmail.com> dateThu 19 Jun 2025, 11:41 (1 year ago) parent81aedae
4 files changed+78−50
internal/tui/components/chat/messages/renderer.go+23−12 internal/tui/components/core/helpers.go+2−1 internal/tui/styles/crush.go+4−3 internal/tui/styles/theme.go+49−34
internal/tui/components/chat/messages/renderer.go+23−12
@@ -600,45 +600,56 @@ func renderPlainContent(v *toolCallCmp, content string) string {
600600 }
601601 out = append(out, t.S().Muted.
602602 Width(width).
603− Background(t.BgSubtle).
603+ Background(t.BgBaseLighter).
604604 Render(ln))
605605 }
606606
607607 if len(lines) > responseContextHeight {
608608 out = append(out, t.S().Muted.
609− Background(t.BgSubtle).
609+ Background(t.BgBaseLighter).
610610 Width(width).
611611 Render(fmt.Sprintf("... (%d lines)", len(lines)-responseContextHeight)))
612612 }
613613 return strings.Join(out, "\n")
614614}
615615
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+
616625func renderCodeContent(v *toolCallCmp, path, content string, offset int) string {
617626 t := styles.CurrentTheme()
618627 truncated := truncateHeight(content, responseContextHeight)
619628
620− highlighted, _ := highlight.SyntaxHighlight(truncated, path, t.BgSubtle)
629+ highlighted, _ := highlight.SyntaxHighlight(truncated, path, t.BgBase)
621630 lines := strings.Split(highlighted, "\n")
622631
623632 if len(strings.Split(content, "\n")) > responseContextHeight {
624633 lines = append(lines, t.S().Muted.
625− Background(t.BgSubtle).
626− Width(v.textWidth()-2).
627− Render(fmt.Sprintf("... (%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
634+ Background(t.BgBase).
635+ Render(fmt.Sprintf(" ... (%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
628636 }
629637
638+ maxLineNumber := len(lines) + offset
639+ padding := lipgloss.Width(fmt.Sprintf("%d", maxLineNumber))
630640 for i, ln := range lines {
631− num := t.S().Muted.
632− Background(t.BgSubtle).
633− PaddingLeft(4).
634− PaddingRight(2).
635− Render(fmt.Sprintf("%d", i+1+offset))
641+ num := t.S().Base.
642+ Foreground(t.FgMuted).
643+ Background(t.BgBase).
644+ PaddingRight(1).
645+ PaddingLeft(1).
646+ Render(pad(i+1+offset, padding))
636647 w := v.textWidth() - 2 - lipgloss.Width(num) // -2 for left padding
637648 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
638649 num,
639650 t.S().Base.
651+ PaddingLeft(1).
640652 Width(w).
641− Background(t.BgSubtle).
642653 Render(v.fit(ln, w)))
643654 }
644655 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 {
148148}
149149
150150func DiffFormatter() *diffview.DiffView {
151+ t := styles.CurrentTheme()
151152 formatDiff := diffview.New()
152153 style := chroma.MustNewStyle("crush", styles.GetChromaTheme())
153− diff := formatDiff.ChromaStyle(style)
154+ diff := formatDiff.ChromaStyle(style).Style(t.S().Diff)
154155 return diff
155156}
internal/tui/styles/crush.go+4−3
@@ -14,9 +14,10 @@ func NewCrushTheme() *Theme {
1414 Tertiary: charmtone.Bok,
1515 Accent: charmtone.Zest,
1616 // Backgrounds
17− BgBase: charmtone.Pepper,
18− BgSubtle: charmtone.Charcoal,
19− BgOverlay: charmtone.Iron,
17+ BgBase: charmtone.Pepper,
18+ BgBaseLighter: Lighten(charmtone.Pepper, 2),
19+ BgSubtle: charmtone.Charcoal,
20+ BgOverlay: charmtone.Iron,
2021
2122 // Foregrounds
2223 FgBase: charmtone.Ash,
internal/tui/styles/theme.go+49−34
@@ -10,6 +10,7 @@ import (
1010 "github.com/charmbracelet/bubbles/v2/textarea"
1111 "github.com/charmbracelet/bubbles/v2/textinput"
1212 tea "github.com/charmbracelet/bubbletea/v2"
13+ "github.com/charmbracelet/crush/internal/exp/diffview"
1314 "github.com/charmbracelet/glamour/v2/ansi"
1415 "github.com/charmbracelet/lipgloss/v2"
1516 "github.com/lucasb-eyer/go-colorful"
@@ -31,9 +32,10 @@ type Theme struct {
3132 Tertiary color.Color
3233 Accent color.Color
3334
34− BgBase color.Color
35− BgSubtle color.Color
36− BgOverlay color.Color
35+ BgBase color.Color
36+ BgBaseLighter color.Color
37+ BgSubtle color.Color
38+ BgOverlay color.Color
3739
3840 FgBase color.Color
3941 FgMuted color.Color
@@ -70,21 +72,6 @@ type Theme struct {
7072 styles *Styles
7173}
7274
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−
8875type Styles struct {
8976 Base lipgloss.Style
9077 SelectedBase lipgloss.Style
@@ -112,7 +99,7 @@ type Styles struct {
11299 Help help.Styles
113100
114101 // Diff
115− Diff Diff
102+ Diff diffview.Style
116103
117104 // FilePicker
118105 FilePicker filepicker.Styles
@@ -421,22 +408,50 @@ func (t *Theme) buildStyles() *Styles {
421408 FullSeparator: base.Foreground(t.Border),
422409 },
423410
424− // TODO: Fix this this is bad
425− Diff: Diff{
426− Added: t.Green,
427− Removed: t.Red,
428− Context: t.FgSubtle,
429− HunkHeader: t.FgSubtle,
430− HighlightAdded: t.GreenLight,
431− HighlightRemoved: t.RedLight,
432− AddedBg: t.GreenDark,
433− RemovedBg: t.RedDark,
434− ContextBg: t.BgSubtle,
435− LineNumber: t.FgMuted,
436− AddedLineNumberBg: t.GreenDark,
437− RemovedLineNumberBg: t.RedDark,
411+ Diff: diffview.Style{
412+ DividerLine: diffview.LineStyle{
413+ LineNumber: lipgloss.NewStyle().
414+ Foreground(t.FgHalfMuted).
415+ Background(t.BgBaseLighter),
416+ Code: lipgloss.NewStyle().
417+ Foreground(t.FgHalfMuted).
418+ Background(t.BgBaseLighter),
419+ },
420+ MissingLine: diffview.LineStyle{
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{
445+ LineNumber: lipgloss.NewStyle().
446+ Foreground(lipgloss.Color("#a45c59")).
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+ },
438454 },
439−
440455 FilePicker: filepicker.Styles{
441456 DisabledCursor: base.Foreground(t.FgMuted),
442457 Cursor: base.Foreground(t.FgBase),