summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-02 13:33:05 -0500
committeradamdottv <[email protected]>2025-06-02 13:33:05 -0500
commitca87b2806f4a021f78b65372a5579920c6b7619d (patch)
tree7898a41cf0115e37ab799185c831bf193bcab262
parent2958c6b53c293d82803b52aec5573dac24c3a9cb (diff)
downloadopencode-ca87b2806f4a021f78b65372a5579920c6b7619d.tar.gz
opencode-ca87b2806f4a021f78b65372a5579920c6b7619d.zip
wip: refactoring tui
-rw-r--r--packages/tui/cmd/root.go11
-rw-r--r--packages/tui/internal/format/format.go46
-rw-r--r--packages/tui/internal/format/format_test.go90
-rw-r--r--packages/tui/internal/tui/components/chat/chat.go3
-rw-r--r--packages/tui/internal/tui/components/core/status.go3
-rw-r--r--packages/tui/internal/version/version.go25
6 files changed, 1 insertions, 177 deletions
diff --git a/packages/tui/cmd/root.go b/packages/tui/cmd/root.go
index 6f0c00f30..d952fc3a3 100644
--- a/packages/tui/cmd/root.go
+++ b/packages/tui/cmd/root.go
@@ -16,7 +16,6 @@ import (
"github.com/sst/opencode/internal/pubsub"
"github.com/sst/opencode/internal/tui"
"github.com/sst/opencode/internal/tui/app"
- "github.com/sst/opencode/internal/version"
)
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
to assist developers in writing, debugging, and understanding code directly from the terminal.`,
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
// file, err := os.OpenFile("debug.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
// if err != nil {
diff --git a/packages/tui/internal/format/format.go b/packages/tui/internal/format/format.go
deleted file mode 100644
index 321f5c102..000000000
--- a/packages/tui/internal/format/format.go
+++ /dev/null
@@ -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)
- }
-}
diff --git a/packages/tui/internal/format/format_test.go b/packages/tui/internal/format/format_test.go
deleted file mode 100644
index 04054a7c4..000000000
--- a/packages/tui/internal/format/format_test.go
+++ /dev/null
@@ -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)
- }
- })
- }
-}
diff --git a/packages/tui/internal/tui/components/chat/chat.go b/packages/tui/internal/tui/components/chat/chat.go
index 2fabea43d..ebebac252 100644
--- a/packages/tui/internal/tui/components/chat/chat.go
+++ b/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/styles"
"github.com/sst/opencode/internal/tui/theme"
- "github.com/sst/opencode/internal/version"
)
type SendMsg struct {
@@ -97,7 +96,7 @@ func logo(width int) string {
versionText := baseStyle.
Foreground(t.TextMuted()).
- Render(version.Version)
+ Render("v0.0.1") // TODO: get version from server
return baseStyle.
Bold(true).
diff --git a/packages/tui/internal/tui/components/core/status.go b/packages/tui/internal/tui/components/core/status.go
index ce9cddf0d..fd47a5701 100644
--- a/packages/tui/internal/tui/components/core/status.go
+++ b/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 {
t := theme.CurrentTheme()
- // modelID := config.Get().Agents[config.AgentPrimary].Model
- // model := models.SupportedModels[modelID]
-
// Initialize the help widget
status := getHelpWidget("")
diff --git a/packages/tui/internal/version/version.go b/packages/tui/internal/version/version.go
deleted file mode 100644
index 69fd5282b..000000000
--- a/packages/tui/internal/version/version.go
+++ /dev/null
@@ -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
-}