summaryrefslogtreecommitdiffhomepage
path: root/internal/tui/components/dialog
diff options
context:
space:
mode:
authorJay V <[email protected]>2025-05-21 15:01:25 -0400
committerJay V <[email protected]>2025-05-21 15:01:25 -0400
commit9049295cc961b250be6144585dde322e778534d7 (patch)
treec8a2f09ed6cea54eb9587243eb7dbe298fef1b20 /internal/tui/components/dialog
parent4526b14b17dc49f3ef4f3b1a1d02eff5c6b6b59f (diff)
parentdff8e77eb6d1709fa1ddeb52d0d9c19afd13d385 (diff)
downloadopencode-9049295cc961b250be6144585dde322e778534d7.tar.gz
opencode-9049295cc961b250be6144585dde322e778534d7.zip
Merge branch 'dev' into docs
Diffstat (limited to 'internal/tui/components/dialog')
-rw-r--r--internal/tui/components/dialog/models.go2
-rw-r--r--internal/tui/components/dialog/permission.go13
-rw-r--r--internal/tui/components/dialog/tools.go178
3 files changed, 190 insertions, 3 deletions
diff --git a/internal/tui/components/dialog/models.go b/internal/tui/components/dialog/models.go
index b21f166ca..d919b5303 100644
--- a/internal/tui/components/dialog/models.go
+++ b/internal/tui/components/dialog/models.go
@@ -10,7 +10,6 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/sst/opencode/internal/config"
"github.com/sst/opencode/internal/llm/models"
- "github.com/sst/opencode/internal/status"
"github.com/sst/opencode/internal/tui/layout"
"github.com/sst/opencode/internal/tui/styles"
"github.com/sst/opencode/internal/tui/theme"
@@ -127,7 +126,6 @@ func (m *modelDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.switchProvider(1)
}
case key.Matches(msg, modelKeys.Enter):
- status.Info(fmt.Sprintf("selected model: %s", m.models[m.selectedIdx].Name))
return m, util.CmdHandler(ModelSelectedMsg{Model: m.models[m.selectedIdx]})
case key.Matches(msg, modelKeys.Escape):
return m, util.CmdHandler(CloseModelDialogMsg{})
diff --git a/internal/tui/components/dialog/permission.go b/internal/tui/components/dialog/permission.go
index d0468d307..5e5b09e1b 100644
--- a/internal/tui/components/dialog/permission.go
+++ b/internal/tui/components/dialog/permission.go
@@ -6,6 +6,7 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
+ "github.com/sst/opencode/internal/config"
"github.com/sst/opencode/internal/diff"
"github.com/sst/opencode/internal/llm/tools"
"github.com/sst/opencode/internal/permission"
@@ -13,6 +14,7 @@ import (
"github.com/sst/opencode/internal/tui/styles"
"github.com/sst/opencode/internal/tui/theme"
"github.com/sst/opencode/internal/tui/util"
+ "path/filepath"
"strings"
)
@@ -204,10 +206,19 @@ func (p *permissionDialogCmp) renderHeader() string {
Render(fmt.Sprintf(": %s", p.permission.ToolName))
pathKey := baseStyle.Foreground(t.TextMuted()).Bold(true).Render("Path")
+
+ // Get the current working directory to display relative path
+ relativePath := p.permission.Path
+ if filepath.IsAbs(relativePath) {
+ if cwd, err := filepath.Rel(config.WorkingDirectory(), relativePath); err == nil {
+ relativePath = cwd
+ }
+ }
+
pathValue := baseStyle.
Foreground(t.Text()).
Width(p.width - lipgloss.Width(pathKey)).
- Render(fmt.Sprintf(": %s", p.permission.Path))
+ Render(fmt.Sprintf(": %s", relativePath))
headerParts := []string{
lipgloss.JoinHorizontal(
diff --git a/internal/tui/components/dialog/tools.go b/internal/tui/components/dialog/tools.go
new file mode 100644
index 000000000..76e6ff227
--- /dev/null
+++ b/internal/tui/components/dialog/tools.go
@@ -0,0 +1,178 @@
+package dialog
+
+import (
+ "github.com/charmbracelet/bubbles/key"
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
+ utilComponents "github.com/sst/opencode/internal/tui/components/util"
+ "github.com/sst/opencode/internal/tui/layout"
+ "github.com/sst/opencode/internal/tui/styles"
+ "github.com/sst/opencode/internal/tui/theme"
+)
+
+const (
+ maxToolsDialogWidth = 60
+ maxVisibleTools = 15
+)
+
+// ToolsDialog interface for the tools list dialog
+type ToolsDialog interface {
+ tea.Model
+ layout.Bindings
+ SetTools(tools []string)
+}
+
+// ShowToolsDialogMsg is sent to show the tools dialog
+type ShowToolsDialogMsg struct {
+ Show bool
+}
+
+// CloseToolsDialogMsg is sent when the tools dialog is closed
+type CloseToolsDialogMsg struct{}
+
+type toolItem struct {
+ name string
+}
+
+func (t toolItem) Render(selected bool, width int) string {
+ th := theme.CurrentTheme()
+ baseStyle := styles.BaseStyle().
+ Width(width).
+ Background(th.Background())
+
+ if selected {
+ baseStyle = baseStyle.
+ Background(th.Primary()).
+ Foreground(th.Background()).
+ Bold(true)
+ } else {
+ baseStyle = baseStyle.
+ Foreground(th.Text())
+ }
+
+ return baseStyle.Render(t.name)
+}
+
+type toolsDialogCmp struct {
+ tools []toolItem
+ width int
+ height int
+ list utilComponents.SimpleList[toolItem]
+}
+
+type toolsKeyMap struct {
+ Up key.Binding
+ Down key.Binding
+ Escape key.Binding
+ J key.Binding
+ K key.Binding
+}
+
+var toolsKeys = toolsKeyMap{
+ Up: key.NewBinding(
+ key.WithKeys("up"),
+ key.WithHelp("↑", "previous tool"),
+ ),
+ Down: key.NewBinding(
+ key.WithKeys("down"),
+ key.WithHelp("↓", "next tool"),
+ ),
+ Escape: key.NewBinding(
+ key.WithKeys("esc"),
+ key.WithHelp("esc", "close"),
+ ),
+ J: key.NewBinding(
+ key.WithKeys("j"),
+ key.WithHelp("j", "next tool"),
+ ),
+ K: key.NewBinding(
+ key.WithKeys("k"),
+ key.WithHelp("k", "previous tool"),
+ ),
+}
+
+func (m *toolsDialogCmp) Init() tea.Cmd {
+ return nil
+}
+
+func (m *toolsDialogCmp) SetTools(tools []string) {
+ var toolItems []toolItem
+ for _, name := range tools {
+ toolItems = append(toolItems, toolItem{name: name})
+ }
+
+ m.tools = toolItems
+ m.list.SetItems(toolItems)
+}
+
+func (m *toolsDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+ switch msg := msg.(type) {
+ case tea.KeyMsg:
+ switch {
+ case key.Matches(msg, toolsKeys.Escape):
+ return m, func() tea.Msg { return CloseToolsDialogMsg{} }
+ // Pass other key messages to the list component
+ default:
+ var cmd tea.Cmd
+ listModel, cmd := m.list.Update(msg)
+ m.list = listModel.(utilComponents.SimpleList[toolItem])
+ return m, cmd
+ }
+ case tea.WindowSizeMsg:
+ m.width = msg.Width
+ m.height = msg.Height
+ }
+
+ // For non-key messages
+ var cmd tea.Cmd
+ listModel, cmd := m.list.Update(msg)
+ m.list = listModel.(utilComponents.SimpleList[toolItem])
+ return m, cmd
+}
+
+func (m *toolsDialogCmp) View() string {
+ t := theme.CurrentTheme()
+ baseStyle := styles.BaseStyle().Background(t.Background())
+
+ title := baseStyle.
+ Foreground(t.Primary()).
+ Bold(true).
+ Width(maxToolsDialogWidth).
+ Padding(0, 0, 1).
+ Render("Available Tools")
+
+ // Calculate dialog width based on content
+ dialogWidth := min(maxToolsDialogWidth, m.width/2)
+ m.list.SetMaxWidth(dialogWidth)
+
+ content := lipgloss.JoinVertical(
+ lipgloss.Left,
+ title,
+ m.list.View(),
+ )
+
+ return baseStyle.Padding(1, 2).
+ Border(lipgloss.RoundedBorder()).
+ BorderBackground(t.Background()).
+ BorderForeground(t.TextMuted()).
+ Background(t.Background()).
+ Width(lipgloss.Width(content) + 4).
+ Render(content)
+}
+
+func (m *toolsDialogCmp) BindingKeys() []key.Binding {
+ return layout.KeyMapToSlice(toolsKeys)
+}
+
+func NewToolsDialogCmp() ToolsDialog {
+ list := utilComponents.NewSimpleList[toolItem](
+ []toolItem{},
+ maxVisibleTools,
+ "No tools available",
+ true,
+ )
+
+ return &toolsDialogCmp{
+ list: list,
+ }
+} \ No newline at end of file