Frank 7 месяцев назад
Родитель
Сommit
01f8d3b05d

+ 32 - 0
packages/tui/internal/components/commands/commands.go

@@ -11,6 +11,7 @@ import (
 	"github.com/sst/opencode/internal/commands"
 	"github.com/sst/opencode/internal/styles"
 	"github.com/sst/opencode/internal/theme"
+	"github.com/sst/opencode/internal/util"
 )
 
 type CommandsComponent interface {
@@ -24,6 +25,7 @@ type commandsComponent struct {
 	width, height int
 	showKeybinds  bool
 	showAll       bool
+	showVscode    bool
 	background    *compat.AdaptiveColor
 	limit         *int
 }
@@ -73,6 +75,30 @@ func (c *commandsComponent) View() string {
 		commandsToShow = commandsToShow[:*c.limit]
 	}
 
+	if c.showVscode {
+		commandsToShow = append(commandsToShow,
+			// empty line
+			commands.Command{
+				Name:        "",
+				Description: "",
+			},
+			commands.Command{
+				Name:        commands.CommandName(util.Ide()),
+				Description: "open opencode",
+				Keybindings: []commands.Keybinding{
+					{Key: "cmd+esc", RequiresLeader: false},
+				},
+			},
+			commands.Command{
+				Name:        commands.CommandName(util.Ide()),
+				Description: "reference file",
+				Keybindings: []commands.Keybinding{
+					{Key: "cmd+opt+k", RequiresLeader: false},
+				},
+			},
+		)
+	}
+
 	if len(commandsToShow) == 0 {
 		muted := styles.NewStyle().Foreground(theme.CurrentTheme().TextMuted())
 		if c.showAll {
@@ -196,6 +222,12 @@ func WithShowAll(showAll bool) Option {
 	}
 }
 
+func WithVscode(showVscode bool) Option {
+	return func(c *commandsComponent) {
+		c.showVscode = showVscode
+	}
+}
+
 func New(app *app.App, opts ...Option) CommandsComponent {
 	c := &commandsComponent{
 		app:          app,

+ 0 - 112
packages/tui/internal/components/ide/ide.go

@@ -1,112 +0,0 @@
-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
-}

+ 3 - 19
packages/tui/internal/tui/tui.go

@@ -24,7 +24,6 @@ import (
 	cmdcomp "github.com/sst/opencode/internal/components/commands"
 	"github.com/sst/opencode/internal/components/dialog"
 	"github.com/sst/opencode/internal/components/fileviewer"
-	"github.com/sst/opencode/internal/components/ide"
 	"github.com/sst/opencode/internal/components/modal"
 	"github.com/sst/opencode/internal/components/status"
 	"github.com/sst/opencode/internal/components/toast"
@@ -654,14 +653,16 @@ func (a Model) home() string {
 
 	// Use limit of 4 for vscode, 6 for others
 	limit := 6
-	if os.Getenv("OPENCODE_CALLER") == "vscode" {
+	if util.IsVSCode() {
 		limit = 4
 	}
 
+	showVscode := util.IsVSCode()
 	commandsView := cmdcomp.New(
 		a.app,
 		cmdcomp.WithBackground(t.Background()),
 		cmdcomp.WithLimit(limit),
+		cmdcomp.WithVscode(showVscode),
 	)
 	cmds := lipgloss.PlaceHorizontal(
 		effectiveWidth,
@@ -670,19 +671,6 @@ func (a Model) home() string {
 		styles.WhitespaceStyle(t.Background()),
 	)
 
-	// Add VSCode shortcuts if in VSCode environment
-	var ideShortcuts string
-	if os.Getenv("OPENCODE_CALLER") == "vscode" {
-		ideView := ide.New()
-		ideView.SetBackgroundColor(t.Background())
-		ideShortcuts = lipgloss.PlaceHorizontal(
-			effectiveWidth,
-			lipgloss.Center,
-			ideView.View(),
-			styles.WhitespaceStyle(t.Background()),
-		)
-	}
-
 	lines := []string{}
 	lines = append(lines, "")
 	lines = append(lines, "")
@@ -690,10 +678,6 @@ func (a Model) home() string {
 	lines = append(lines, "")
 	lines = append(lines, "")
 	lines = append(lines, cmds)
-	if os.Getenv("OPENCODE_CALLER") == "vscode" {
-		lines = append(lines, "")
-		lines = append(lines, ideShortcuts)
-	}
 	lines = append(lines, "")
 	lines = append(lines, "")
 

+ 30 - 0
packages/tui/internal/util/ide.go

@@ -0,0 +1,30 @@
+package util
+
+import (
+	"os"
+	"strings"
+)
+
+var SUPPORTED_IDES = []struct {
+	Search string
+	ShortName string
+}{
+	{"Windsurf", "Windsurf"},
+	{"Visual Studio Code", "VS Code"},
+	{"Cursor", "Cursor"},
+	{"VSCodium", "VSCodium"},
+}
+
+func IsVSCode() bool {
+	return os.Getenv("OPENCODE_CALLER") == "vscode"
+}
+
+func Ide() string {
+	for _, ide := range SUPPORTED_IDES {
+		if strings.Contains(os.Getenv("GIT_ASKPASS"), ide.Search) {
+			return ide.ShortName
+		}
+	}
+
+	return "unknown"
+}