diff options
| author | adamdottv <[email protected]> | 2025-06-12 05:35:40 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-12 16:00:24 -0500 |
| commit | cce2e4ad754479917fc8f6f24c1421cf19c04573 (patch) | |
| tree | 62c0ec32358932a468af73b44fd28e7de7859bbe /packages/tui/internal/components/diff/diff.go | |
| parent | a1ce35c208bf9ebca37f722e845035bd7fd5e801 (diff) | |
| download | opencode-cce2e4ad754479917fc8f6f24c1421cf19c04573.tar.gz opencode-cce2e4ad754479917fc8f6f24c1421cf19c04573.zip | |
wip: refactoring tui
Diffstat (limited to 'packages/tui/internal/components/diff/diff.go')
| -rw-r--r-- | packages/tui/internal/components/diff/diff.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/packages/tui/internal/components/diff/diff.go b/packages/tui/internal/components/diff/diff.go index 65874ebb4..4551cf736 100644 --- a/packages/tui/internal/components/diff/diff.go +++ b/packages/tui/internal/components/diff/diff.go @@ -3,6 +3,7 @@ package diff import ( "bytes" "fmt" + "image/color" "io" "regexp" "strconv" @@ -12,9 +13,11 @@ import ( "github.com/alecthomas/chroma/v2/formatters" "github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/styles" - "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/lipgloss/v2" + "github.com/charmbracelet/lipgloss/v2/compat" "github.com/charmbracelet/x/ansi" "github.com/sergi/go-diff/diffmatchpatch" + stylesi "github.com/sst/opencode/internal/styles" "github.com/sst/opencode/internal/theme" ) @@ -300,7 +303,7 @@ func pairLines(lines []DiffLine) []linePair { // ------------------------------------------------------------------------- // SyntaxHighlight applies syntax highlighting to text based on file extension -func SyntaxHighlight(w io.Writer, source, fileName, formatter string, bg lipgloss.TerminalColor) error { +func SyntaxHighlight(w io.Writer, source, fileName, formatter string, bg color.Color) error { t := theme.CurrentTheme() // Determine the language lexer to use @@ -509,15 +512,12 @@ func SyntaxHighlight(w io.Writer, source, fileName, formatter string, bg lipglos } // getColor returns the appropriate hex color string based on terminal background -func getColor(adaptiveColor lipgloss.AdaptiveColor) string { - if lipgloss.HasDarkBackground() { - return adaptiveColor.Dark - } - return adaptiveColor.Light +func getColor(adaptiveColor compat.AdaptiveColor) string { + return stylesi.AdaptiveColorToString(adaptiveColor) } // highlightLine applies syntax highlighting to a single line -func highlightLine(fileName string, line string, bg lipgloss.TerminalColor) string { +func highlightLine(fileName string, line string, bg color.Color) string { var buf bytes.Buffer err := SyntaxHighlight(&buf, line, fileName, "terminal16m", bg) if err != nil { @@ -540,7 +540,7 @@ func createStyles(t theme.Theme) (removedLineStyle, addedLineStyle, contextLineS // ------------------------------------------------------------------------- // applyHighlighting applies intra-line highlighting to a piece of text -func applyHighlighting(content string, segments []Segment, segmentType LineType, highlightBg lipgloss.AdaptiveColor) string { +func applyHighlighting(content string, segments []Segment, segmentType LineType, highlightBg compat.AdaptiveColor) string { // Find all ANSI sequences in the content ansiRegex := regexp.MustCompile(`\x1b(?:[@-Z\\-_]|\[[0-9?]*(?:;[0-9?]*)*[@-~])`) ansiMatches := ansiRegex.FindAllStringIndex(content, -1) @@ -662,7 +662,7 @@ func renderDiffColumnLine( var bgStyle lipgloss.Style var lineNum string var highlightType LineType - var highlightColor lipgloss.AdaptiveColor + var highlightColor compat.AdaptiveColor if isLeftColumn { // Left column logic |
