From cce2e4ad754479917fc8f6f24c1421cf19c04573 Mon Sep 17 00:00:00 2001 From: adamdottv <2363879+adamdottv@users.noreply.github.com> Date: Thu, 12 Jun 2025 05:35:40 -0500 Subject: wip: refactoring tui --- packages/tui/internal/components/diff/diff.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'packages/tui/internal/components/diff') 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 -- cgit v1.2.3