Browse Source

some small fixes

Kujtim Hoxha 9 months ago
parent
commit
e4680caebb

+ 17 - 10
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)
 	}
 

+ 0 - 5
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

+ 2 - 2
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)
 }

+ 4 - 4
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{

+ 0 - 159
internal/tui/styles/huh.go

@@ -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
-}
-

+ 2 - 2
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 {