diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-12 14:49:01 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-21 13:38:42 +0200 |
| commit | 0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345 (patch) | |
| tree | 9b45cabbb2c8f0195d8428445db4d8a710db7951 /internal/tui/styles | |
| parent | 8d874b839db169906e18e4277cd198504018e022 (diff) | |
| download | opencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.tar.gz opencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.zip | |
implement nested tool calls and initial setup for result metadata
Diffstat (limited to 'internal/tui/styles')
| -rw-r--r-- | internal/tui/styles/background.go | 81 | ||||
| -rw-r--r-- | internal/tui/styles/markdown.go | 7 | ||||
| -rw-r--r-- | internal/tui/styles/styles.go | 10 |
3 files changed, 95 insertions, 3 deletions
diff --git a/internal/tui/styles/background.go b/internal/tui/styles/background.go new file mode 100644 index 000000000..bf6cbc105 --- /dev/null +++ b/internal/tui/styles/background.go @@ -0,0 +1,81 @@ +package styles + +import ( + "fmt" + "regexp" + "strconv" + "strings" + + "github.com/charmbracelet/lipgloss" +) + +var ansiEscape = regexp.MustCompile("\x1b\\[[0-9;]*m") + +func getColorRGB(c lipgloss.TerminalColor) (uint8, uint8, uint8) { + r, g, b, a := c.RGBA() + + // Un-premultiply alpha if needed + if a > 0 && a < 0xffff { + r = (r * 0xffff) / a + g = (g * 0xffff) / a + b = (b * 0xffff) / a + } + + // Convert from 16-bit to 8-bit color + return uint8(r >> 8), uint8(g >> 8), uint8(b >> 8) +} + +func ForceReplaceBackgroundWithLipgloss(input string, newBgColor lipgloss.TerminalColor) string { + r, g, b := getColorRGB(newBgColor) + + newBg := fmt.Sprintf("48;2;%d;%d;%d", r, g, b) + + return ansiEscape.ReplaceAllStringFunc(input, func(seq string) string { + // Extract content between "\x1b[" and "m" + content := seq[2 : len(seq)-1] + tokens := strings.Split(content, ";") + var newTokens []string + + // Skip background color tokens + for i := 0; i < len(tokens); i++ { + if tokens[i] == "" { + continue + } + + val, err := strconv.Atoi(tokens[i]) + if err != nil { + newTokens = append(newTokens, tokens[i]) + continue + } + + // Skip background color tokens + if val == 48 { + // Skip "48;5;N" or "48;2;R;G;B" sequences + if i+1 < len(tokens) { + if nextVal, err := strconv.Atoi(tokens[i+1]); err == nil { + switch nextVal { + case 5: + i += 2 // Skip "5" and color index + case 2: + i += 4 // Skip "2" and RGB components + } + } + } + } else if (val < 40 || val > 47) && (val < 100 || val > 107) && val != 49 { + // Keep non-background tokens + newTokens = append(newTokens, tokens[i]) + } + } + + // Add new background if provided + if newBg != "" { + newTokens = append(newTokens, strings.Split(newBg, ";")...) + } + + if len(newTokens) == 0 { + return "" + } + + return "\x1b[" + strings.Join(newTokens, ";") + "m" + }) +} diff --git a/internal/tui/styles/markdown.go b/internal/tui/styles/markdown.go index b4e71c51e..52816eab3 100644 --- a/internal/tui/styles/markdown.go +++ b/internal/tui/styles/markdown.go @@ -515,6 +515,7 @@ var ASCIIStyleConfig = ansi.StyleConfig{ Document: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ BackgroundColor: stringPtr(Background.Dark), + Color: stringPtr(ForgroundDim.Dark), }, Indent: uintPtr(1), IndentToken: stringPtr(BaseStyle.Render(" ")), @@ -688,7 +689,7 @@ var DraculaStyleConfig = ansi.StyleConfig{ Heading: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ BlockSuffix: "\n", - Color: stringPtr("#bd93f9"), + Color: stringPtr(PrimaryColor.Dark), Bold: boolPtr(true), BackgroundColor: stringPtr(Background.Dark), }, @@ -740,7 +741,7 @@ var DraculaStyleConfig = ansi.StyleConfig{ }, Strong: ansi.StylePrimitive{ Bold: boolPtr(true), - Color: stringPtr("#ffb86c"), + Color: stringPtr(Blue.Dark), BackgroundColor: stringPtr(Background.Dark), }, HorizontalRule: ansi.StylePrimitive{ @@ -796,7 +797,7 @@ var DraculaStyleConfig = ansi.StyleConfig{ CodeBlock: ansi.StyleCodeBlock{ StyleBlock: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ - Color: stringPtr("#ffb86c"), + Color: stringPtr(Blue.Dark), BackgroundColor: stringPtr(Background.Dark), }, Margin: uintPtr(defaultMargin), diff --git a/internal/tui/styles/styles.go b/internal/tui/styles/styles.go index 41863cf1b..476339b57 100644 --- a/internal/tui/styles/styles.go +++ b/internal/tui/styles/styles.go @@ -34,6 +34,11 @@ var ( Light: "#d3d3d3", } + ForgroundMid = lipgloss.AdaptiveColor{ + Dark: "#a0a0a0", + Light: "#a0a0a0", + } + ForgroundDim = lipgloss.AdaptiveColor{ Dark: "#737373", Light: "#737373", @@ -159,6 +164,11 @@ var ( Light: light.Peach().Hex, } + Yellow = lipgloss.AdaptiveColor{ + Dark: dark.Yellow().Hex, + Light: light.Yellow().Hex, + } + Primary = Blue Secondary = Mauve |
