diff options
| author | adamdottv <[email protected]> | 2025-06-18 13:56:46 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-18 13:56:51 -0500 |
| commit | bd46cf0f868293b501874c1f04632ced3bec7b81 (patch) | |
| tree | bcd5ed78fc41bcf73c0ffd76086bf10c34ed700b /packages/tui/internal/components/dialog | |
| parent | d4157d9a9603c099e650af4f6c369a56d3878179 (diff) | |
| download | opencode-bd46cf0f868293b501874c1f04632ced3bec7b81.tar.gz opencode-bd46cf0f868293b501874c1f04632ced3bec7b81.zip | |
feat(tui): configurable keybinds and mouse scroll
Diffstat (limited to 'packages/tui/internal/components/dialog')
| -rw-r--r-- | packages/tui/internal/components/dialog/complete.go | 9 | ||||
| -rw-r--r-- | packages/tui/internal/components/dialog/help.go | 54 |
2 files changed, 27 insertions, 36 deletions
diff --git a/packages/tui/internal/components/dialog/complete.go b/packages/tui/internal/components/dialog/complete.go index ca86b00e6..c627e96e9 100644 --- a/packages/tui/internal/components/dialog/complete.go +++ b/packages/tui/internal/components/dialog/complete.go @@ -1,6 +1,8 @@ package dialog import ( + "log/slog" + "github.com/charmbracelet/bubbles/v2/key" "github.com/charmbracelet/bubbles/v2/textarea" tea "github.com/charmbracelet/bubbletea/v2" @@ -144,6 +146,7 @@ func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { c.list.SetItems(msg) case tea.KeyMsg: if c.pseudoSearchTextArea.Focused() { + slog.Info("CompletionDialog", "key", msg.String(), "focused", true) if !key.Matches(msg, completionDialogKeys.Complete) { var cmd tea.Cmd c.pseudoSearchTextArea, cmd = c.pseudoSearchTextArea.Update(msg) @@ -159,10 +162,10 @@ func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { c.query = query cmd = func() tea.Msg { items, err := c.completionProvider.GetChildEntries(query) + slog.Info("CompletionDialog", "query", query, "items", len(items)) if err != nil { - // status.Error(err.Error()) + slog.Error("Failed to get completion items", "error", err) } - // c.list.SetItems(items) return items } cmds = append(cmds, cmd) @@ -189,9 +192,11 @@ func (c *completionDialogComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return c, tea.Batch(cmds...) } else { + slog.Info("CompletionDialog", "key", msg.String(), "focused", false) cmd := func() tea.Msg { items, err := c.completionProvider.GetChildEntries("") if err != nil { + slog.Error("Failed to get completion items", "error", err) // status.Error(err.Error()) } return items diff --git a/packages/tui/internal/components/dialog/help.go b/packages/tui/internal/components/dialog/help.go index 2ef887890..1886714e4 100644 --- a/packages/tui/internal/components/dialog/help.go +++ b/packages/tui/internal/components/dialog/help.go @@ -3,9 +3,9 @@ package dialog import ( "strings" - "github.com/charmbracelet/bubbles/v2/key" tea "github.com/charmbracelet/bubbletea/v2" "github.com/charmbracelet/lipgloss/v2" + "github.com/sst/opencode/internal/commands" "github.com/sst/opencode/internal/components/modal" "github.com/sst/opencode/internal/layout" "github.com/sst/opencode/internal/theme" @@ -15,28 +15,9 @@ type helpDialog struct { width int height int modal *modal.Modal - bindings []key.Binding + commands commands.CommandRegistry } -// func (i bindingItem) Render(selected bool, width int) string { -// t := theme.CurrentTheme() -// baseStyle := styles.BaseStyle(). -// Width(width - 2). -// Background(t.BackgroundElement()) -// -// if selected { -// baseStyle = baseStyle. -// Background(t.Primary()). -// Foreground(t.BackgroundElement()). -// Bold(true) -// } else { -// baseStyle = baseStyle. -// Foreground(t.Text()) -// } -// -// return baseStyle.Padding(0, 1).Render(i.binding.Help().Desc) -// } - func (h *helpDialog) Init() tea.Cmd { return nil } @@ -63,19 +44,24 @@ func (h *helpDialog) View() string { PaddingLeft(1).Background(t.BackgroundElement()) lines := []string{} - for _, b := range h.bindings { - content := keyStyle.Render(b.Help().Key) - content += descStyle.Render(" " + b.Help().Desc) - for i, key := range b.Keys() { - if i == 0 { - keyString := " (" + strings.ToUpper(key) + ")" - // space := max(h.width-lipgloss.Width(content)-lipgloss.Width(keyString), 0) - // spacer := strings.Repeat(" ", space) - // content += descStyle.Render(spacer) - content += descStyle.Render(keyString) - } + for _, b := range h.commands { + // Only interested in slash commands + if b.Trigger == "" { + continue } + content := keyStyle.Render("/" + b.Trigger) + content += descStyle.Render(" " + b.Description) + // for i, key := range b.Keybindings { + // if i == 0 { + // keyString := " (" + key.Key + ")" + // space := max(h.width-lipgloss.Width(content)-lipgloss.Width(keyString), 0) + // spacer := strings.Repeat(" ", space) + // content += descStyle.Render(spacer) + // content += descStyle.Render(keyString) + // } + // } + lines = append(lines, contentStyle.Render(content)) } @@ -94,9 +80,9 @@ type HelpDialog interface { layout.Modal } -func NewHelpDialog(bindings ...key.Binding) HelpDialog { +func NewHelpDialog(commands commands.CommandRegistry) HelpDialog { return &helpDialog{ - bindings: bindings, + commands: commands, modal: modal.New(), } } |
