Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 4a74863

Browse files
committed
cleanup old components
1 parent d9f7a41 commit 4a74863

14 files changed

Lines changed: 633 additions & 1847 deletions

File tree

internal/diff/diff.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/charmbracelet/x/ansi"
1313
"github.com/opencode-ai/opencode/internal/config"
1414
"github.com/opencode-ai/opencode/internal/highlight"
15-
"github.com/opencode-ai/opencode/internal/tui/theme"
15+
"github.com/opencode-ai/opencode/internal/tui/styles"
1616
"github.com/sergi/go-diff/diffmatchpatch"
1717
)
1818

@@ -329,12 +329,11 @@ func highlightLine(fileName string, line string, bg color.Color) string {
329329
}
330330

331331
// createStyles generates the lipgloss styles needed for rendering diffs
332-
func createStyles(t theme.Theme) (removedLineStyle, addedLineStyle, contextLineStyle, lineNumberStyle lipgloss.Style) {
333-
removedLineStyle = lipgloss.NewStyle().Background(t.DiffRemovedBg())
334-
addedLineStyle = lipgloss.NewStyle().Background(t.DiffAddedBg())
335-
contextLineStyle = lipgloss.NewStyle().Background(t.DiffContextBg())
336-
lineNumberStyle = lipgloss.NewStyle().Foreground(t.DiffLineNumber())
337-
332+
func createStyles(t *styles.Theme) (removedLineStyle, addedLineStyle, contextLineStyle, lineNumberStyle lipgloss.Style) {
333+
removedLineStyle = lipgloss.NewStyle().Background(t.S().Diff.RemovedBg)
334+
addedLineStyle = lipgloss.NewStyle().Background(t.S().Diff.AddedBg)
335+
contextLineStyle = lipgloss.NewStyle().Background(t.S().Diff.ContextBg)
336+
lineNumberStyle = lipgloss.NewStyle().Foreground(t.S().Diff.LineNumber)
338337
return
339338
}
340339

@@ -446,10 +445,10 @@ func applyHighlighting(content string, segments []Segment, segmentType LineType,
446445

447446
// renderLeftColumn formats the left side of a side-by-side diff
448447
func renderLeftColumn(fileName string, dl *DiffLine, colWidth int) string {
449-
t := theme.CurrentTheme()
448+
t := styles.CurrentTheme()
450449

451450
if dl == nil {
452-
contextLineStyle := lipgloss.NewStyle().Background(t.DiffContextBg())
451+
contextLineStyle := t.S().Base.Background(t.S().Diff.ContextBg)
453452
return contextLineStyle.Width(colWidth).Render("")
454453
}
455454

@@ -460,9 +459,9 @@ func renderLeftColumn(fileName string, dl *DiffLine, colWidth int) string {
460459
var bgStyle lipgloss.Style
461460
switch dl.Kind {
462461
case LineRemoved:
463-
marker = removedLineStyle.Foreground(t.DiffRemoved()).Render("-")
462+
marker = removedLineStyle.Foreground(t.S().Diff.Removed).Render("-")
464463
bgStyle = removedLineStyle
465-
lineNumberStyle = lineNumberStyle.Foreground(t.DiffRemoved()).Background(t.DiffRemovedLineNumberBg())
464+
lineNumberStyle = lineNumberStyle.Foreground(t.S().Diff.Removed).Background(t.S().Diff.RemovedLineNumberBg)
466465
case LineAdded:
467466
marker = "?"
468467
bgStyle = contextLineStyle
@@ -485,7 +484,7 @@ func renderLeftColumn(fileName string, dl *DiffLine, colWidth int) string {
485484

486485
// Apply intra-line highlighting for removed lines
487486
if dl.Kind == LineRemoved && len(dl.Segments) > 0 {
488-
content = applyHighlighting(content, dl.Segments, LineRemoved, t.DiffHighlightRemoved())
487+
content = applyHighlighting(content, dl.Segments, LineRemoved, t.S().Diff.HighlightRemoved)
489488
}
490489

491490
// Add a padding space for removed lines
@@ -499,17 +498,17 @@ func renderLeftColumn(fileName string, dl *DiffLine, colWidth int) string {
499498
ansi.Truncate(
500499
lineText,
501500
colWidth,
502-
lipgloss.NewStyle().Background(bgStyle.GetBackground()).Foreground(t.TextMuted()).Render("..."),
501+
lipgloss.NewStyle().Background(bgStyle.GetBackground()).Foreground(t.FgMuted).Render("..."),
503502
),
504503
)
505504
}
506505

507506
// renderRightColumn formats the right side of a side-by-side diff
508507
func renderRightColumn(fileName string, dl *DiffLine, colWidth int) string {
509-
t := theme.CurrentTheme()
508+
t := styles.CurrentTheme()
510509

511510
if dl == nil {
512-
contextLineStyle := lipgloss.NewStyle().Background(t.DiffContextBg())
511+
contextLineStyle := lipgloss.NewStyle().Background(t.S().Diff.ContextBg)
513512
return contextLineStyle.Width(colWidth).Render("")
514513
}
515514

@@ -520,9 +519,9 @@ func renderRightColumn(fileName string, dl *DiffLine, colWidth int) string {
520519
var bgStyle lipgloss.Style
521520
switch dl.Kind {
522521
case LineAdded:
523-
marker = addedLineStyle.Foreground(t.DiffAdded()).Render("+")
522+
marker = addedLineStyle.Foreground(t.S().Diff.Added).Render("+")
524523
bgStyle = addedLineStyle
525-
lineNumberStyle = lineNumberStyle.Foreground(t.DiffAdded()).Background(t.DiffAddedLineNumberBg())
524+
lineNumberStyle = lineNumberStyle.Foreground(t.S().Diff.Added).Background(t.S().Diff.AddedLineNumberBg)
526525
case LineRemoved:
527526
marker = "?"
528527
bgStyle = contextLineStyle
@@ -545,7 +544,7 @@ func renderRightColumn(fileName string, dl *DiffLine, colWidth int) string {
545544

546545
// Apply intra-line highlighting for added lines
547546
if dl.Kind == LineAdded && len(dl.Segments) > 0 {
548-
content = applyHighlighting(content, dl.Segments, LineAdded, t.DiffHighlightAdded())
547+
content = applyHighlighting(content, dl.Segments, LineAdded, t.S().Diff.HighlightAdded)
549548
}
550549

551550
// Add a padding space for added lines
@@ -559,7 +558,7 @@ func renderRightColumn(fileName string, dl *DiffLine, colWidth int) string {
559558
ansi.Truncate(
560559
lineText,
561560
colWidth,
562-
lipgloss.NewStyle().Background(bgStyle.GetBackground()).Foreground(t.TextMuted()).Render("..."),
561+
lipgloss.NewStyle().Background(bgStyle.GetBackground()).Foreground(t.FgMuted).Render("..."),
563562
),
564563
)
565564
}

internal/highlight/highlight.go

Lines changed: 4 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import (
44
"bytes"
55
"fmt"
66
"image/color"
7-
"strings"
87

98
"github.com/alecthomas/chroma/v2"
109
"github.com/alecthomas/chroma/v2/formatters"
1110
"github.com/alecthomas/chroma/v2/lexers"
12-
"github.com/alecthomas/chroma/v2/styles"
13-
"github.com/opencode-ai/opencode/internal/tui/theme"
11+
chromaStyles "github.com/alecthomas/chroma/v2/styles"
12+
"github.com/opencode-ai/opencode/internal/tui/styles"
1413
)
1514

1615
func SyntaxHighlight(source, fileName string, bg color.Color) (string, error) {
17-
t := theme.CurrentTheme()
18-
1916
// Determine the language lexer to use
2017
l := lexers.Match(fileName)
2118
if l == nil {
@@ -32,171 +29,7 @@ func SyntaxHighlight(source, fileName string, bg color.Color) (string, error) {
3229
f = formatters.Fallback
3330
}
3431

35-
// Dynamic theme based on current theme values
36-
syntaxThemeXml := fmt.Sprintf(`
37-
<style name="opencode-theme">
38-
<!-- Base colors -->
39-
<entry type="Text" style="%s"/>
40-
<entry type="Other" style="%s"/>
41-
<entry type="Error" style="%s"/>
42-
<!-- Keywords -->
43-
<entry type="Keyword" style="%s"/>
44-
<entry type="KeywordConstant" style="%s"/>
45-
<entry type="KeywordDeclaration" style="%s"/>
46-
<entry type="KeywordNamespace" style="%s"/>
47-
<entry type="KeywordPseudo" style="%s"/>
48-
<entry type="KeywordReserved" style="%s"/>
49-
<entry type="KeywordType" style="%s"/>
50-
<!-- Names -->
51-
<entry type="Name" style="%s"/>
52-
<entry type="NameAttribute" style="%s"/>
53-
<entry type="NameBuiltin" style="%s"/>
54-
<entry type="NameBuiltinPseudo" style="%s"/>
55-
<entry type="NameClass" style="%s"/>
56-
<entry type="NameConstant" style="%s"/>
57-
<entry type="NameDecorator" style="%s"/>
58-
<entry type="NameEntity" style="%s"/>
59-
<entry type="NameException" style="%s"/>
60-
<entry type="NameFunction" style="%s"/>
61-
<entry type="NameLabel" style="%s"/>
62-
<entry type="NameNamespace" style="%s"/>
63-
<entry type="NameOther" style="%s"/>
64-
<entry type="NameTag" style="%s"/>
65-
<entry type="NameVariable" style="%s"/>
66-
<entry type="NameVariableClass" style="%s"/>
67-
<entry type="NameVariableGlobal" style="%s"/>
68-
<entry type="NameVariableInstance" style="%s"/>
69-
<!-- Literals -->
70-
<entry type="Literal" style="%s"/>
71-
<entry type="LiteralDate" style="%s"/>
72-
<entry type="LiteralString" style="%s"/>
73-
<entry type="LiteralStringBacktick" style="%s"/>
74-
<entry type="LiteralStringChar" style="%s"/>
75-
<entry type="LiteralStringDoc" style="%s"/>
76-
<entry type="LiteralStringDouble" style="%s"/>
77-
<entry type="LiteralStringEscape" style="%s"/>
78-
<entry type="LiteralStringHeredoc" style="%s"/>
79-
<entry type="LiteralStringInterpol" style="%s"/>
80-
<entry type="LiteralStringOther" style="%s"/>
81-
<entry type="LiteralStringRegex" style="%s"/>
82-
<entry type="LiteralStringSingle" style="%s"/>
83-
<entry type="LiteralStringSymbol" style="%s"/>
84-
<!-- Numbers -->
85-
<entry type="LiteralNumber" style="%s"/>
86-
<entry type="LiteralNumberBin" style="%s"/>
87-
<entry type="LiteralNumberFloat" style="%s"/>
88-
<entry type="LiteralNumberHex" style="%s"/>
89-
<entry type="LiteralNumberInteger" style="%s"/>
90-
<entry type="LiteralNumberIntegerLong" style="%s"/>
91-
<entry type="LiteralNumberOct" style="%s"/>
92-
<!-- Operators -->
93-
<entry type="Operator" style="%s"/>
94-
<entry type="OperatorWord" style="%s"/>
95-
<entry type="Punctuation" style="%s"/>
96-
<!-- Comments -->
97-
<entry type="Comment" style="%s"/>
98-
<entry type="CommentHashbang" style="%s"/>
99-
<entry type="CommentMultiline" style="%s"/>
100-
<entry type="CommentSingle" style="%s"/>
101-
<entry type="CommentSpecial" style="%s"/>
102-
<entry type="CommentPreproc" style="%s"/>
103-
<!-- Generic styles -->
104-
<entry type="Generic" style="%s"/>
105-
<entry type="GenericDeleted" style="%s"/>
106-
<entry type="GenericEmph" style="italic %s"/>
107-
<entry type="GenericError" style="%s"/>
108-
<entry type="GenericHeading" style="bold %s"/>
109-
<entry type="GenericInserted" style="%s"/>
110-
<entry type="GenericOutput" style="%s"/>
111-
<entry type="GenericPrompt" style="%s"/>
112-
<entry type="GenericStrong" style="bold %s"/>
113-
<entry type="GenericSubheading" style="bold %s"/>
114-
<entry type="GenericTraceback" style="%s"/>
115-
<entry type="GenericUnderline" style="underline"/>
116-
<entry type="TextWhitespace" style="%s"/>
117-
</style>
118-
`,
119-
getColor(t.Text()), // Text
120-
getColor(t.Text()), // Other
121-
getColor(t.Error()), // Error
122-
123-
getColor(t.SyntaxKeyword()), // Keyword
124-
getColor(t.SyntaxKeyword()), // KeywordConstant
125-
getColor(t.SyntaxKeyword()), // KeywordDeclaration
126-
getColor(t.SyntaxKeyword()), // KeywordNamespace
127-
getColor(t.SyntaxKeyword()), // KeywordPseudo
128-
getColor(t.SyntaxKeyword()), // KeywordReserved
129-
getColor(t.SyntaxType()), // KeywordType
130-
131-
getColor(t.Text()), // Name
132-
getColor(t.SyntaxVariable()), // NameAttribute
133-
getColor(t.SyntaxType()), // NameBuiltin
134-
getColor(t.SyntaxVariable()), // NameBuiltinPseudo
135-
getColor(t.SyntaxType()), // NameClass
136-
getColor(t.SyntaxVariable()), // NameConstant
137-
getColor(t.SyntaxFunction()), // NameDecorator
138-
getColor(t.SyntaxVariable()), // NameEntity
139-
getColor(t.SyntaxType()), // NameException
140-
getColor(t.SyntaxFunction()), // NameFunction
141-
getColor(t.Text()), // NameLabel
142-
getColor(t.SyntaxType()), // NameNamespace
143-
getColor(t.SyntaxVariable()), // NameOther
144-
getColor(t.SyntaxKeyword()), // NameTag
145-
getColor(t.SyntaxVariable()), // NameVariable
146-
getColor(t.SyntaxVariable()), // NameVariableClass
147-
getColor(t.SyntaxVariable()), // NameVariableGlobal
148-
getColor(t.SyntaxVariable()), // NameVariableInstance
149-
150-
getColor(t.SyntaxString()), // Literal
151-
getColor(t.SyntaxString()), // LiteralDate
152-
getColor(t.SyntaxString()), // LiteralString
153-
getColor(t.SyntaxString()), // LiteralStringBacktick
154-
getColor(t.SyntaxString()), // LiteralStringChar
155-
getColor(t.SyntaxString()), // LiteralStringDoc
156-
getColor(t.SyntaxString()), // LiteralStringDouble
157-
getColor(t.SyntaxString()), // LiteralStringEscape
158-
getColor(t.SyntaxString()), // LiteralStringHeredoc
159-
getColor(t.SyntaxString()), // LiteralStringInterpol
160-
getColor(t.SyntaxString()), // LiteralStringOther
161-
getColor(t.SyntaxString()), // LiteralStringRegex
162-
getColor(t.SyntaxString()), // LiteralStringSingle
163-
getColor(t.SyntaxString()), // LiteralStringSymbol
164-
165-
getColor(t.SyntaxNumber()), // LiteralNumber
166-
getColor(t.SyntaxNumber()), // LiteralNumberBin
167-
getColor(t.SyntaxNumber()), // LiteralNumberFloat
168-
getColor(t.SyntaxNumber()), // LiteralNumberHex
169-
getColor(t.SyntaxNumber()), // LiteralNumberInteger
170-
getColor(t.SyntaxNumber()), // LiteralNumberIntegerLong
171-
getColor(t.SyntaxNumber()), // LiteralNumberOct
172-
173-
getColor(t.SyntaxOperator()), // Operator
174-
getColor(t.SyntaxKeyword()), // OperatorWord
175-
getColor(t.SyntaxPunctuation()), // Punctuation
176-
177-
getColor(t.SyntaxComment()), // Comment
178-
getColor(t.SyntaxComment()), // CommentHashbang
179-
getColor(t.SyntaxComment()), // CommentMultiline
180-
getColor(t.SyntaxComment()), // CommentSingle
181-
getColor(t.SyntaxComment()), // CommentSpecial
182-
getColor(t.SyntaxKeyword()), // CommentPreproc
183-
184-
getColor(t.Text()), // Generic
185-
getColor(t.Error()), // GenericDeleted
186-
getColor(t.Text()), // GenericEmph
187-
getColor(t.Error()), // GenericError
188-
getColor(t.Text()), // GenericHeading
189-
getColor(t.Success()), // GenericInserted
190-
getColor(t.TextMuted()), // GenericOutput
191-
getColor(t.Text()), // GenericPrompt
192-
getColor(t.Text()), // GenericStrong
193-
getColor(t.Text()), // GenericSubheading
194-
getColor(t.Error()), // GenericTraceback
195-
getColor(t.Text()), // TextWhitespace
196-
)
197-
198-
r := strings.NewReader(syntaxThemeXml)
199-
style := chroma.MustNewXMLStyle(r)
32+
style := chroma.MustNewStyle("crush", styles.GetChromaTheme())
20033

20134
// Modify the style to use the provided background
20235
s, err := style.Builder().Transform(
@@ -207,7 +40,7 @@ func SyntaxHighlight(source, fileName string, bg color.Color) (string, error) {
20740
},
20841
).Build()
20942
if err != nil {
210-
s = styles.Fallback
43+
s = chromaStyles.Fallback
21144
}
21245

21346
// Tokenize and format

internal/tui/components/anim/anim.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package anim
22

33
import (
4+
"fmt"
45
"image/color"
56
"math/rand"
67
"strings"
@@ -12,7 +13,6 @@ import (
1213
"github.com/google/uuid"
1314
"github.com/lucasb-eyer/go-colorful"
1415
"github.com/opencode-ai/opencode/internal/tui/styles"
15-
"github.com/opencode-ai/opencode/internal/tui/theme"
1616
"github.com/opencode-ai/opencode/internal/tui/util"
1717
)
1818

@@ -240,7 +240,7 @@ func (a *anim) updateChars(chars *[]cyclingChar) {
240240

241241
// View renders the animation.
242242
func (a anim) View() tea.View {
243-
t := theme.CurrentTheme()
243+
t := styles.CurrentTheme()
244244
var b strings.Builder
245245

246246
for i, c := range a.cyclingChars {
@@ -252,8 +252,7 @@ func (a anim) View() tea.View {
252252
}
253253

254254
if len(a.labelChars) > 1 {
255-
textStyle := styles.BaseStyle().
256-
Foreground(t.Text())
255+
textStyle := t.S().Text
257256
for _, c := range a.labelChars {
258257
b.WriteString(
259258
textStyle.Render(string(c.currentValue)),
@@ -265,10 +264,15 @@ func (a anim) View() tea.View {
265264
return tea.NewView(b.String())
266265
}
267266

267+
func GetColor(c color.Color) string {
268+
rgba := color.RGBAModel.Convert(c).(color.RGBA)
269+
return fmt.Sprintf("#%02x%02x%02x", rgba.R, rgba.G, rgba.B)
270+
}
271+
268272
func makeGradientRamp(length int) []color.Color {
269-
t := theme.CurrentTheme()
270-
startColor := theme.GetColor(t.Primary())
271-
endColor := theme.GetColor(t.Secondary())
273+
t := styles.CurrentTheme()
274+
startColor := GetColor(t.Primary)
275+
endColor := GetColor(t.Secondary)
272276
var (
273277
c = make([]color.Color, length)
274278
start, _ = colorful.Hex(startColor)

0 commit comments

Comments
 (0)