summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components/list
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-22 05:34:22 -0500
committeradamdottv <[email protected]>2025-06-22 05:34:22 -0500
commit3ea2daaa4c1fef54c3e827300a63bd3b41b88806 (patch)
tree17e2aabe13ecf01a2aa047cc9fec00ae604b864c /packages/tui/internal/components/list
parent137e964131703704e99a632b3aa0351ab4921fae (diff)
downloadopencode-3ea2daaa4c1fef54c3e827300a63bd3b41b88806.tar.gz
opencode-3ea2daaa4c1fef54c3e827300a63bd3b41b88806.zip
fix(tui): theme dialog visuals
Diffstat (limited to 'packages/tui/internal/components/list')
-rw-r--r--packages/tui/internal/components/list/list.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/tui/internal/components/list/list.go b/packages/tui/internal/components/list/list.go
index cd0bf18c0..c6ddbaf7e 100644
--- a/packages/tui/internal/components/list/list.go
+++ b/packages/tui/internal/components/list/list.go
@@ -5,6 +5,9 @@ import (
"github.com/charmbracelet/bubbles/v2/key"
tea "github.com/charmbracelet/bubbletea/v2"
+ "github.com/charmbracelet/lipgloss/v2"
+ "github.com/sst/opencode/internal/styles"
+ "github.com/sst/opencode/internal/theme"
)
type ListItem interface {
@@ -123,6 +126,9 @@ func (c *listComponent[T]) SetSelectedIndex(idx int) {
func (c *listComponent[T]) View() string {
items := c.items
maxWidth := c.maxWidth
+ if maxWidth == 0 {
+ maxWidth = 80 // Default width if not set
+ }
maxVisibleItems := min(c.maxVisibleItems, len(items))
startIdx := 0
@@ -161,3 +167,34 @@ func NewListComponent[T ListItem](items []T, maxVisibleItems int, fallbackMsg st
selectedIdx: 0,
}
}
+
+// StringItem is a simple implementation of ListItem for string values
+type StringItem string
+
+func (s StringItem) Render(selected bool, width int) string {
+ t := theme.CurrentTheme()
+ baseStyle := styles.BaseStyle()
+
+ var itemStyle lipgloss.Style
+ if selected {
+ itemStyle = baseStyle.
+ Background(t.Primary()).
+ Foreground(t.Background()).
+ Width(width).
+ PaddingLeft(1)
+ } else {
+ itemStyle = baseStyle.
+ PaddingLeft(1)
+ }
+
+ return itemStyle.Render(string(s))
+}
+
+// NewStringList creates a new list component with string items
+func NewStringList(items []string, maxVisibleItems int, fallbackMsg string, useAlphaNumericKeys bool) List[StringItem] {
+ stringItems := make([]StringItem, len(items))
+ for i, item := range items {
+ stringItems[i] = StringItem(item)
+ }
+ return NewListComponent(stringItems, maxVisibleItems, fallbackMsg, useAlphaNumericKeys)
+}