Ver código fonte

wip: refactoring tui

adamdottv 8 meses atrás
pai
commit
863e7a093e

+ 9 - 0
packages/tui/internal/tui/app/app.go

@@ -18,6 +18,12 @@ import (
 )
 
 type App struct {
+	Paths *struct {
+		Config string `json:"config"`
+		Cwd    string `json:"cwd"`
+		Data   string `json:"data"`
+		Root   string `json:"root"`
+	}
 	Client   *client.ClientWithResponses
 	Events   *client.Client
 	Provider *client.ProviderInfo
@@ -57,10 +63,13 @@ func New(ctx context.Context) (*App, error) {
 		return nil, err
 	}
 
+	paths, _ := httpClient.PostPathGetWithResponse(context.Background())
+
 	// Create service bridges
 	agentBridge := NewAgentServiceBridge(httpClient)
 
 	app := &App{
+		Paths:           paths.JSON200,
 		Client:          httpClient,
 		Events:          eventClient,
 		Session:         &client.SessionInfo{},

+ 4 - 5
packages/tui/internal/tui/components/chat/chat.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/charmbracelet/lipgloss"
 	"github.com/charmbracelet/x/ansi"
-	"github.com/sst/opencode/internal/config"
 	"github.com/sst/opencode/internal/tui/app"
 	"github.com/sst/opencode/internal/tui/styles"
 	"github.com/sst/opencode/internal/tui/theme"
@@ -17,13 +16,13 @@ type SendMsg struct {
 	Attachments []app.Attachment
 }
 
-func header(width int) string {
+func header(app *app.App, width int) string {
 	return lipgloss.JoinVertical(
 		lipgloss.Top,
 		logo(width),
 		repo(width),
 		"",
-		cwd(width),
+		cwd(app, width),
 	)
 }
 
@@ -121,8 +120,8 @@ func repo(width int) string {
 		Render(repo)
 }
 
-func cwd(width int) string {
-	cwd := fmt.Sprintf("cwd: %s", config.WorkingDirectory())
+func cwd(app *app.App, width int) string {
+	cwd := fmt.Sprintf("cwd: %s", app.Paths.Cwd)
 	t := theme.CurrentTheme()
 
 	return styles.BaseStyle().

+ 1 - 1
packages/tui/internal/tui/components/chat/messages.go

@@ -278,7 +278,7 @@ func (m *messagesCmp) initialScreen() string {
 	return baseStyle.Width(m.width).Render(
 		lipgloss.JoinVertical(
 			lipgloss.Top,
-			header(m.width),
+			header(m.app, m.width),
 			"",
 			lspsConfigured(m.width),
 		),

+ 1 - 1
packages/tui/internal/tui/components/chat/sidebar.go

@@ -71,7 +71,7 @@ func (m *sidebarCmp) View() string {
 		Render(
 			lipgloss.JoinVertical(
 				lipgloss.Top,
-				header(m.width),
+				header(m.app, m.width),
 				" ",
 				m.sessionSection(),
 				shareUrl,