summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components/dialog
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-13 15:56:30 -0500
committeradamdottv <[email protected]>2025-06-13 15:56:33 -0500
commit67023bb00710b6a40836800da2eb5cdacc1ee9c1 (patch)
tree4c6fce2842956f214b8e39a7465d4444b37d39b0 /packages/tui/internal/components/dialog
parenta316aed4fe973682667a19e6ba550270cf1a9df4 (diff)
downloadopencode-67023bb00710b6a40836800da2eb5cdacc1ee9c1.tar.gz
opencode-67023bb00710b6a40836800da2eb5cdacc1ee9c1.zip
wip: refactoring tui
Diffstat (limited to 'packages/tui/internal/components/dialog')
-rw-r--r--packages/tui/internal/components/dialog/complete.go57
-rw-r--r--packages/tui/internal/components/dialog/session.go8
-rw-r--r--packages/tui/internal/components/dialog/theme.go8
3 files changed, 44 insertions, 29 deletions
diff --git a/packages/tui/internal/components/dialog/complete.go b/packages/tui/internal/components/dialog/complete.go
index 8819184ac..fbf5c79f1 100644
--- a/packages/tui/internal/components/dialog/complete.go
+++ b/packages/tui/internal/components/dialog/complete.go
@@ -5,7 +5,7 @@ import (
"github.com/charmbracelet/bubbles/v2/textarea"
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/lipgloss/v2"
- utilComponents "github.com/sst/opencode/internal/components/util"
+ "github.com/sst/opencode/internal/components/list"
"github.com/sst/opencode/internal/layout"
"github.com/sst/opencode/internal/status"
"github.com/sst/opencode/internal/styles"
@@ -20,7 +20,7 @@ type CompletionItem struct {
}
type CompletionItemI interface {
- utilComponents.ListItem
+ list.ListItem
GetValue() string
DisplayValue() string
}
@@ -30,18 +30,18 @@ func (ci *CompletionItem) Render(selected bool, width int) string {
baseStyle := styles.BaseStyle()
itemStyle := baseStyle.
+ Background(t.BackgroundElement()).
Width(width).
Padding(0, 1)
if selected {
itemStyle = itemStyle.
- Background(t.Background()).
Foreground(t.Primary()).
Bold(true)
}
title := itemStyle.Render(
- ci.GetValue(),
+ ci.DisplayValue(),
)
return title
@@ -68,6 +68,7 @@ type CompletionProvider interface {
type CompletionSelectedMsg struct {
SearchString string
CompletionValue string
+ IsCommand bool
}
type CompletionDialogCompleteItemMsg struct {
@@ -80,6 +81,7 @@ type CompletionDialog interface {
layout.ModelWithView
SetWidth(width int)
IsEmpty() bool
+ SetProvider(provider CompletionProvider)
}
type completionDialogComponent struct {
@@ -88,7 +90,7 @@ type completionDialogComponent struct {
width int
height int
pseudoSearchTextArea textarea.Model
- list utilComponents.List[CompletionItemI]
+ list list.List[CompletionItemI]
}
type completionDialogKeyMap struct {
@@ -116,10 +118,14 @@ func (c *completionDialogComponent) complete(item CompletionItemI) tea.Cmd {
return nil
}
+ // Check if this is a command completion
+ isCommand := c.completionProvider.GetId() == "commands"
+
return tea.Batch(
util.CmdHandler(CompletionSelectedMsg{
SearchString: value,
CompletionValue: item.GetValue(),
+ IsCommand: isCommand,
}),
c.close(),
)
@@ -160,7 +166,7 @@ func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
u, cmd := c.list.Update(msg)
- c.list = u.(utilComponents.List[CompletionItemI])
+ c.list = u.(list.List[CompletionItemI])
cmds = append(cmds, cmd)
}
@@ -171,8 +177,7 @@ func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if i == -1 {
return c, nil
}
- cmd := c.complete(item)
- return c, cmd
+ return c, c.complete(item)
case key.Matches(msg, completionDialogKeys.Cancel):
// Only close on backspace when there are no characters left
if msg.String() != "backspace" || len(c.pseudoSearchTextArea.Value()) <= 0 {
@@ -203,21 +208,20 @@ func (c *completionDialogComponent) View() string {
t := theme.CurrentTheme()
baseStyle := styles.BaseStyle()
- // maxWidth := 40
- //
- // completions := c.list.GetItems()
+ maxWidth := 40
+ completions := c.list.GetItems()
- // for _, cmd := range completions {
- // title := cmd.DisplayValue()
- // if len(title) > maxWidth-4 {
- // maxWidth = len(title) + 4
- // }
- // }
+ for _, cmd := range completions {
+ title := cmd.DisplayValue()
+ if len(title) > maxWidth-4 {
+ maxWidth = len(title) + 4
+ }
+ }
- // c.list.SetMaxWidth(maxWidth)
+ c.list.SetMaxWidth(maxWidth)
return baseStyle.Padding(0, 0).
- Background(t.BackgroundSubtle()).
+ Background(t.BackgroundElement()).
Border(lipgloss.ThickBorder()).
BorderTop(false).
BorderBottom(false).
@@ -236,6 +240,17 @@ func (c *completionDialogComponent) IsEmpty() bool {
return c.list.IsEmpty()
}
+func (c *completionDialogComponent) SetProvider(provider CompletionProvider) {
+ if c.completionProvider.GetId() != provider.GetId() {
+ c.completionProvider = provider
+ items, err := provider.GetChildEntries("")
+ if err != nil {
+ status.Error(err.Error())
+ }
+ c.list.SetItems(items)
+ }
+}
+
func NewCompletionDialogComponent(completionProvider CompletionProvider) CompletionDialog {
ti := textarea.New()
@@ -244,10 +259,10 @@ func NewCompletionDialogComponent(completionProvider CompletionProvider) Complet
status.Error(err.Error())
}
- li := utilComponents.NewListComponent(
+ li := list.NewListComponent(
items,
7,
- "No matching files",
+ "No matches",
false,
)
diff --git a/packages/tui/internal/components/dialog/session.go b/packages/tui/internal/components/dialog/session.go
index 4a41c71f3..48278d85e 100644
--- a/packages/tui/internal/components/dialog/session.go
+++ b/packages/tui/internal/components/dialog/session.go
@@ -5,8 +5,8 @@ import (
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/sst/opencode/internal/app"
+ "github.com/sst/opencode/internal/components/list"
"github.com/sst/opencode/internal/components/modal"
- components "github.com/sst/opencode/internal/components/util"
"github.com/sst/opencode/internal/layout"
"github.com/sst/opencode/internal/state"
"github.com/sst/opencode/internal/styles"
@@ -48,7 +48,7 @@ type sessionDialog struct {
height int
modal *modal.Modal
selectedSessionID string
- list components.List[sessionItem]
+ list list.List[sessionItem]
}
func (s *sessionDialog) Init() tea.Cmd {
@@ -77,7 +77,7 @@ func (s *sessionDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
listModel, cmd := s.list.Update(msg)
- s.list = listModel.(components.List[sessionItem])
+ s.list = listModel.(list.List[sessionItem])
return s, cmd
}
@@ -98,7 +98,7 @@ func NewSessionDialog(app *app.App) SessionDialog {
sessionItems = append(sessionItems, sessionItem{session: sess})
}
- list := components.NewListComponent(
+ list := list.NewListComponent(
sessionItems,
10, // maxVisibleSessions
"No sessions available",
diff --git a/packages/tui/internal/components/dialog/theme.go b/packages/tui/internal/components/dialog/theme.go
index 2febc1fe0..f045b1b09 100644
--- a/packages/tui/internal/components/dialog/theme.go
+++ b/packages/tui/internal/components/dialog/theme.go
@@ -2,8 +2,8 @@ package dialog
import (
tea "github.com/charmbracelet/bubbletea/v2"
+ list "github.com/sst/opencode/internal/components/list"
"github.com/sst/opencode/internal/components/modal"
- components "github.com/sst/opencode/internal/components/util"
"github.com/sst/opencode/internal/layout"
"github.com/sst/opencode/internal/status"
"github.com/sst/opencode/internal/styles"
@@ -49,7 +49,7 @@ type themeDialog struct {
height int
modal *modal.Modal
- list components.List[themeItem]
+ list list.List[themeItem]
}
func (t *themeDialog) Init() tea.Cmd {
@@ -84,7 +84,7 @@ func (t *themeDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
listModel, cmd := t.list.Update(msg)
- t.list = listModel.(components.List[themeItem])
+ t.list = listModel.(list.List[themeItem])
return t, cmd
}
@@ -110,7 +110,7 @@ func NewThemeDialog() ThemeDialog {
}
}
- list := components.NewListComponent(
+ list := list.NewListComponent(
themeItems,
10, // maxVisibleThemes
"No themes available",