Browse Source

wip: refactoring tui

adamdottv 8 months ago
parent
commit
ca87b2806f

+ 0 - 11
packages/tui/cmd/root.go

@@ -16,7 +16,6 @@ import (
 	"github.com/sst/opencode/internal/pubsub"
 	"github.com/sst/opencode/internal/pubsub"
 	"github.com/sst/opencode/internal/tui"
 	"github.com/sst/opencode/internal/tui"
 	"github.com/sst/opencode/internal/tui/app"
 	"github.com/sst/opencode/internal/tui/app"
-	"github.com/sst/opencode/internal/version"
 )
 )
 
 
 var rootCmd = &cobra.Command{
 var rootCmd = &cobra.Command{
@@ -26,16 +25,6 @@ var rootCmd = &cobra.Command{
 It provides an interactive chat interface with AI capabilities, code analysis, and LSP integration
 It provides an interactive chat interface with AI capabilities, code analysis, and LSP integration
 to assist developers in writing, debugging, and understanding code directly from the terminal.`,
 to assist developers in writing, debugging, and understanding code directly from the terminal.`,
 	RunE: func(cmd *cobra.Command, args []string) error {
 	RunE: func(cmd *cobra.Command, args []string) error {
-		// If the help flag is set, show the help message
-		if cmd.Flag("help").Changed {
-			cmd.Help()
-			return nil
-		}
-		if cmd.Flag("version").Changed {
-			fmt.Println(version.Version)
-			return nil
-		}
-
 		// Setup logging
 		// Setup logging
 		// file, err := os.OpenFile("debug.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
 		// file, err := os.OpenFile("debug.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
 		// if err != nil {
 		// if err != nil {

+ 0 - 46
packages/tui/internal/format/format.go

@@ -1,46 +0,0 @@
-package format
-
-import (
-	"encoding/json"
-	"fmt"
-)
-
-// OutputFormat represents the format for non-interactive mode output
-type OutputFormat string
-
-const (
-	// TextFormat is plain text output (default)
-	TextFormat OutputFormat = "text"
-
-	// JSONFormat is output wrapped in a JSON object
-	JSONFormat OutputFormat = "json"
-)
-
-// IsValid checks if the output format is valid
-func (f OutputFormat) IsValid() bool {
-	return f == TextFormat || f == JSONFormat
-}
-
-// String returns the string representation of the output format
-func (f OutputFormat) String() string {
-	return string(f)
-}
-
-// FormatOutput formats the given content according to the specified format
-func FormatOutput(content string, format OutputFormat) (string, error) {
-	switch format {
-	case TextFormat:
-		return content, nil
-	case JSONFormat:
-		jsonData := map[string]string{
-			"response": content,
-		}
-		jsonBytes, err := json.MarshalIndent(jsonData, "", "  ")
-		if err != nil {
-			return "", fmt.Errorf("failed to marshal JSON: %w", err)
-		}
-		return string(jsonBytes), nil
-	default:
-		return "", fmt.Errorf("unsupported output format: %s", format)
-	}
-}

+ 0 - 90
packages/tui/internal/format/format_test.go

@@ -1,90 +0,0 @@
-package format
-
-import (
-	"testing"
-)
-
-func TestOutputFormat_IsValid(t *testing.T) {
-	t.Parallel()
-
-	tests := []struct {
-		name   string
-		format OutputFormat
-		want   bool
-	}{
-		{
-			name:   "text format",
-			format: TextFormat,
-			want:   true,
-		},
-		{
-			name:   "json format",
-			format: JSONFormat,
-			want:   true,
-		},
-		{
-			name:   "invalid format",
-			format: "invalid",
-			want:   false,
-		},
-	}
-
-	for _, tt := range tests {
-		tt := tt
-		t.Run(tt.name, func(t *testing.T) {
-			t.Parallel()
-			if got := tt.format.IsValid(); got != tt.want {
-				t.Errorf("OutputFormat.IsValid() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
-
-func TestFormatOutput(t *testing.T) {
-	t.Parallel()
-
-	tests := []struct {
-		name    string
-		content string
-		format  OutputFormat
-		want    string
-		wantErr bool
-	}{
-		{
-			name:    "text format",
-			content: "test content",
-			format:  TextFormat,
-			want:    "test content",
-			wantErr: false,
-		},
-		{
-			name:    "json format",
-			content: "test content",
-			format:  JSONFormat,
-			want:    "{\n  \"response\": \"test content\"\n}",
-			wantErr: false,
-		},
-		{
-			name:    "invalid format",
-			content: "test content",
-			format:  "invalid",
-			want:    "",
-			wantErr: true,
-		},
-	}
-
-	for _, tt := range tests {
-		tt := tt
-		t.Run(tt.name, func(t *testing.T) {
-			t.Parallel()
-			got, err := FormatOutput(tt.content, tt.format)
-			if (err != nil) != tt.wantErr {
-				t.Errorf("FormatOutput() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
-			if got != tt.want {
-				t.Errorf("FormatOutput() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}

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

@@ -10,7 +10,6 @@ import (
 	"github.com/sst/opencode/internal/tui/app"
 	"github.com/sst/opencode/internal/tui/app"
 	"github.com/sst/opencode/internal/tui/styles"
 	"github.com/sst/opencode/internal/tui/styles"
 	"github.com/sst/opencode/internal/tui/theme"
 	"github.com/sst/opencode/internal/tui/theme"
-	"github.com/sst/opencode/internal/version"
 )
 )
 
 
 type SendMsg struct {
 type SendMsg struct {
@@ -97,7 +96,7 @@ func logo(width int) string {
 
 
 	versionText := baseStyle.
 	versionText := baseStyle.
 		Foreground(t.TextMuted()).
 		Foreground(t.TextMuted()).
-		Render(version.Version)
+		Render("v0.0.1") // TODO: get version from server
 
 
 	return baseStyle.
 	return baseStyle.
 		Bold(true).
 		Bold(true).

+ 0 - 3
packages/tui/internal/tui/components/core/status.go

@@ -145,9 +145,6 @@ func formatTokensAndCost(tokens float32, contextWindow float32, cost float32) st
 
 
 func (m statusCmp) View() string {
 func (m statusCmp) View() string {
 	t := theme.CurrentTheme()
 	t := theme.CurrentTheme()
-	// modelID := config.Get().Agents[config.AgentPrimary].Model
-	// model := models.SupportedModels[modelID]
-
 	// Initialize the help widget
 	// Initialize the help widget
 	status := getHelpWidget("")
 	status := getHelpWidget("")
 
 

+ 0 - 25
packages/tui/internal/version/version.go

@@ -1,25 +0,0 @@
-package version
-
-import "runtime/debug"
-
-// Build-time parameters set via -ldflags
-var Version = "unknown"
-
-// A user may install pug using `go install github.com/sst/opencode@latest`.
-// without -ldflags, in which case the version above is unset. As a workaround
-// we use the embedded build version that *is* set when using `go install` (and
-// is only set for `go install` and not for `go build`).
-func init() {
-	info, ok := debug.ReadBuildInfo()
-	if !ok {
-		// < go v1.18
-		return
-	}
-	mainVersion := info.Main.Version
-	if mainVersion == "" || mainVersion == "(devel)" {
-		// bin not built using `go install`
-		return
-	}
-	// bin built using `go install`
-	Version = mainVersion
-}