summaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-05-01 12:48:19 +0200
committeradamdottv <[email protected]>2025-05-01 11:07:47 -0500
commite4680caebb7235988450f6b1d59da2e46a78e567 (patch)
tree94b4a560276748b86c67684b6c3053d587076787 /internal
parente760d28c5a125f7f4de30cf0491be53e32bb897d (diff)
downloadopencode-e4680caebb7235988450f6b1d59da2e46a78e567.tar.gz
opencode-e4680caebb7235988450f6b1d59da2e46a78e567.zip
some small fixes
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go27
-rw-r--r--internal/tui/components/chat/message.go5
-rw-r--r--internal/tui/components/core/status.go4
-rw-r--r--internal/tui/components/logs/table.go8
-rw-r--r--internal/tui/styles/huh.go159
-rw-r--r--internal/tui/tui.go4
6 files changed, 25 insertions, 182 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 88f3a1838..eec694450 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -6,6 +6,7 @@ import (
"fmt"
"log/slog"
"os"
+ "path/filepath"
"strings"
"github.com/opencode-ai/opencode/internal/llm/models"
@@ -735,16 +736,22 @@ func UpdateTheme(themeName string) error {
// Get the config file path
configFile := viper.ConfigFileUsed()
+ var configData []byte
if configFile == "" {
- // If no config file exists yet, create one with default settings
- viper.Set("tui.theme", themeName)
- return viper.SafeWriteConfig()
- }
-
- // Read the existing config file
- configData, err := os.ReadFile(configFile)
- if err != nil {
- return fmt.Errorf("failed to read config file: %w", err)
+ homeDir, err := os.UserHomeDir()
+ if err != nil {
+ return fmt.Errorf("failed to get home directory: %w", err)
+ }
+ configFile = filepath.Join(homeDir, fmt.Sprintf(".%s.json", appName))
+ logging.Info("config file not found, creating new one", "path", configFile)
+ configData = []byte(`{}`)
+ } else {
+ // Read the existing config file
+ data, err := os.ReadFile(configFile)
+ if err != nil {
+ return fmt.Errorf("failed to read config file: %w", err)
+ }
+ configData = data
}
// Parse the JSON
@@ -770,7 +777,7 @@ func UpdateTheme(themeName string) error {
return fmt.Errorf("failed to marshal config: %w", err)
}
- if err := os.WriteFile(configFile, updatedData, 0644); err != nil {
+ if err := os.WriteFile(configFile, updatedData, 0o644); err != nil {
return fmt.Errorf("failed to write config file: %w", err)
}
diff --git a/internal/tui/components/chat/message.go b/internal/tui/components/chat/message.go
index f8d721f19..5163ec735 100644
--- a/internal/tui/components/chat/message.go
+++ b/internal/tui/components/chat/message.go
@@ -30,11 +30,6 @@ const (
maxResultHeight = 10
)
-// getDiffWidth returns the width for the diff formatting
-func getDiffWidth(width int) int {
- return width
-}
-
type uiMessage struct {
ID string
messageType uiMessageType
diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go
index ca02265e1..28120a430 100644
--- a/internal/tui/components/core/status.go
+++ b/internal/tui/components/core/status.go
@@ -21,7 +21,7 @@ import (
type StatusCmp interface {
tea.Model
- SetHelpMsg(string)
+ SetHelpWidgetMsg(string)
}
type statusCmp struct {
@@ -263,7 +263,7 @@ func (m statusCmp) model() string {
Render(model.Name)
}
-func (m statusCmp) SetHelpMsg(s string) {
+func (m statusCmp) SetHelpWidgetMsg(s string) {
// Update the help widget text using the getHelpWidget function
helpWidget = getHelpWidget(s)
}
diff --git a/internal/tui/components/logs/table.go b/internal/tui/components/logs/table.go
index b9386cb73..8d59f967f 100644
--- a/internal/tui/components/logs/table.go
+++ b/internal/tui/components/logs/table.go
@@ -63,6 +63,9 @@ func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (i *tableCmp) View() string {
t := theme.CurrentTheme()
+ defaultStyles := table.DefaultStyles()
+ defaultStyles.Selected = defaultStyles.Selected.Foreground(t.Primary())
+ i.table.SetStyles(defaultStyles)
return styles.ForceReplaceBackgroundWithLipgloss(i.table.View(), t.Background())
}
@@ -116,7 +119,6 @@ func (i *tableCmp) setRows() {
}
func NewLogsTable() TableComponent {
- t := theme.CurrentTheme()
columns := []table.Column{
{Title: "ID", Width: 4},
{Title: "Time", Width: 4},
@@ -124,11 +126,9 @@ func NewLogsTable() TableComponent {
{Title: "Message", Width: 10},
{Title: "Attributes", Width: 10},
}
- defaultStyles := table.DefaultStyles()
- defaultStyles.Selected = defaultStyles.Selected.Foreground(t.Primary())
+
tableModel := table.New(
table.WithColumns(columns),
- table.WithStyles(defaultStyles),
)
tableModel.Focus()
return &tableCmp{
diff --git a/internal/tui/styles/huh.go b/internal/tui/styles/huh.go
deleted file mode 100644
index 8df454c1f..000000000
--- a/internal/tui/styles/huh.go
+++ /dev/null
@@ -1,159 +0,0 @@
-package styles
-
-import (
- "github.com/charmbracelet/huh"
- "github.com/charmbracelet/lipgloss"
- "github.com/opencode-ai/opencode/internal/tui/theme"
-)
-
-// returns a huh.Theme configured with the current app theme colors
-func HuhTheme() *huh.Theme {
- t := huh.ThemeBase()
- currentTheme := theme.CurrentTheme()
-
- // Base theme elements
- bgColor := currentTheme.Background()
- bgSecondaryColor := currentTheme.BackgroundSecondary()
- textColor := currentTheme.Text()
- textMutedColor := currentTheme.TextMuted()
- primaryColor := currentTheme.Primary()
- secondaryColor := currentTheme.Secondary()
- // accentColor := currentTheme.Accent()
- errorColor := currentTheme.Error()
- successColor := currentTheme.Success()
- // warningColor := currentTheme.Warning()
- // infoColor := currentTheme.Info()
- borderColor := currentTheme.BorderNormal()
- borderFocusedColor := currentTheme.BorderFocused()
-
- // Focused styles
- t.Focused.Base = t.Focused.Base.
- BorderStyle(lipgloss.HiddenBorder()).
- Background(bgColor).
- BorderForeground(borderColor)
-
- t.Focused.Title = t.Focused.Title.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.NoteTitle = t.Focused.NoteTitle.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.Directory = t.Focused.Directory.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.Description = t.Focused.Description.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Focused.ErrorIndicator = t.Focused.ErrorIndicator.
- Foreground(errorColor).
- Background(bgColor)
-
- t.Focused.ErrorMessage = t.Focused.ErrorMessage.
- Foreground(errorColor).
- Background(bgColor)
-
- t.Focused.SelectSelector = t.Focused.SelectSelector.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Focused.NextIndicator = t.Focused.NextIndicator.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Focused.PrevIndicator = t.Focused.PrevIndicator.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Focused.Option = t.Focused.Option.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.MultiSelectSelector = t.Focused.MultiSelectSelector.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Focused.SelectedOption = t.Focused.SelectedOption.
- Foreground(successColor).
- Background(bgColor)
-
- t.Focused.SelectedPrefix = t.Focused.SelectedPrefix.
- Foreground(successColor).
- Background(bgColor)
-
- t.Focused.UnselectedPrefix = t.Focused.UnselectedPrefix.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.UnselectedOption = t.Focused.UnselectedOption.
- Foreground(textColor).
- Background(bgColor)
-
- t.Focused.FocusedButton = t.Focused.FocusedButton.
- Foreground(bgColor).
- Background(primaryColor).
- BorderForeground(borderFocusedColor)
-
- t.Focused.BlurredButton = t.Focused.BlurredButton.
- Foreground(textColor).
- Background(bgSecondaryColor).
- BorderForeground(borderColor)
-
- // Text input styles
- t.Focused.TextInput.Cursor = t.Focused.TextInput.Cursor.
- Foreground(secondaryColor).
- Background(bgColor)
-
- t.Focused.TextInput.Placeholder = t.Focused.TextInput.Placeholder.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Focused.TextInput.Prompt = t.Focused.TextInput.Prompt.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Focused.TextInput.Text = t.Focused.TextInput.Text.
- Foreground(textColor).
- Background(bgColor)
-
- // Blur and focus states should be similar
- t.Blurred = t.Focused
- t.Blurred.Base = t.Blurred.Base.
- BorderStyle(lipgloss.HiddenBorder()).
- Background(bgColor)
-
- // Help styles
- t.Help.Ellipsis = t.Help.Ellipsis.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Help.ShortKey = t.Help.ShortKey.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Help.ShortDesc = t.Help.ShortDesc.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Help.ShortSeparator = t.Help.ShortSeparator.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Help.FullKey = t.Help.FullKey.
- Foreground(primaryColor).
- Background(bgColor)
-
- t.Help.FullDesc = t.Help.FullDesc.
- Foreground(textMutedColor).
- Background(bgColor)
-
- t.Help.FullSeparator = t.Help.FullSeparator.
- Foreground(textMutedColor).
- Background(bgColor)
-
- return t
-}
-
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index cfaa78170..28f94add7 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -558,9 +558,9 @@ func (a appModel) View() string {
}
if !a.app.CoderAgent.IsBusy() {
- a.status.SetHelpMsg("ctrl+? help")
+ a.status.SetHelpWidgetMsg("ctrl+? help")
} else {
- a.status.SetHelpMsg("? help")
+ a.status.SetHelpWidgetMsg("? help")
}
if a.showHelp {