summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-07-21 19:10:51 -0400
committerFrank <[email protected]>2025-07-21 19:10:57 -0400
commit5611ef8b28216aa9dd2ceb6ed17d5779a29154f6 (patch)
treea58c6dceb5f0e6243a6cbe3e4dc87a259119fd10 /packages/tui/internal/components
parentbec796e3c3c097bfc7bb9090729ec23573151d79 (diff)
downloadopencode-5611ef8b28216aa9dd2ceb6ed17d5779a29154f6.tar.gz
opencode-5611ef8b28216aa9dd2ceb6ed17d5779a29154f6.zip
wip: vscode extension
Diffstat (limited to 'packages/tui/internal/components')
-rw-r--r--packages/tui/internal/components/ide/ide.go112
1 files changed, 112 insertions, 0 deletions
diff --git a/packages/tui/internal/components/ide/ide.go b/packages/tui/internal/components/ide/ide.go
new file mode 100644
index 000000000..cb10f0fc9
--- /dev/null
+++ b/packages/tui/internal/components/ide/ide.go
@@ -0,0 +1,112 @@
+package ide
+
+import (
+ "fmt"
+ "strings"
+
+ tea "github.com/charmbracelet/bubbletea/v2"
+ "github.com/charmbracelet/lipgloss/v2"
+ "github.com/charmbracelet/lipgloss/v2/compat"
+ "github.com/sst/opencode/internal/styles"
+ "github.com/sst/opencode/internal/theme"
+)
+
+type IdeComponent interface {
+ tea.ViewModel
+ SetSize(width, height int) tea.Cmd
+ SetBackgroundColor(color compat.AdaptiveColor)
+}
+
+type ideComponent struct {
+ width, height int
+ background *compat.AdaptiveColor
+}
+
+func (c *ideComponent) SetSize(width, height int) tea.Cmd {
+ c.width = width
+ c.height = height
+ return nil
+}
+
+func (c *ideComponent) SetBackgroundColor(color compat.AdaptiveColor) {
+ c.background = &color
+}
+
+func (c *ideComponent) View() string {
+ t := theme.CurrentTheme()
+
+ triggerStyle := styles.NewStyle().Foreground(t.Primary()).Bold(true)
+ descriptionStyle := styles.NewStyle().Foreground(t.Text())
+
+ if c.background != nil {
+ triggerStyle = triggerStyle.Background(*c.background)
+ descriptionStyle = descriptionStyle.Background(*c.background)
+ }
+
+ // VSCode shortcuts data
+ shortcuts := []struct {
+ shortcut string
+ description string
+ }{
+ {"Cmd+Esc", "open opencode in VS Code"},
+ {"Cmd+Opt+K", "insert file from VS Code"},
+ }
+
+ // Calculate column widths
+ maxShortcutWidth := 0
+ maxDescriptionWidth := 0
+
+ for _, shortcut := range shortcuts {
+ if len(shortcut.shortcut) > maxShortcutWidth {
+ maxShortcutWidth = len(shortcut.shortcut)
+ }
+ if len(shortcut.description) > maxDescriptionWidth {
+ maxDescriptionWidth = len(shortcut.description)
+ }
+ }
+
+ // Add padding between columns
+ columnPadding := 3
+
+ // Build the output
+ var output strings.Builder
+
+ maxWidth := 0
+ for _, shortcut := range shortcuts {
+ // Pad each column to align properly
+ shortcutText := fmt.Sprintf("%-*s", maxShortcutWidth, shortcut.shortcut)
+ description := fmt.Sprintf("%-*s", maxDescriptionWidth, shortcut.description)
+
+ // Apply styles and combine
+ line := triggerStyle.Render(shortcutText) +
+ triggerStyle.Render(strings.Repeat(" ", columnPadding)) +
+ descriptionStyle.Render(description)
+
+ output.WriteString(line + "\n")
+ maxWidth = max(maxWidth, lipgloss.Width(line))
+ }
+
+ // Remove trailing newline
+ result := strings.TrimSuffix(output.String(), "\n")
+ if c.background != nil {
+ result = styles.NewStyle().Background(*c.background).Width(maxWidth).Render(result)
+ }
+
+ return result
+}
+
+type Option func(*ideComponent)
+
+func WithBackground(background compat.AdaptiveColor) Option {
+ return func(c *ideComponent) {
+ c.background = &background
+ }
+}
+
+func New(opts ...Option) IdeComponent {
+ c := &ideComponent{}
+ for _, opt := range opts {
+ opt(c)
+ }
+ return c
+}