Skip to content

Commit 1144664

Browse files
committed
feat: add a theme cli command
1 parent 1a3c3fe commit 1144664

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

internal/cmd/theme.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/charmbracelet/crush/internal/config"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var themeCmd = &cobra.Command{
11+
Use: "theme",
12+
Short: "Manage TUI themes",
13+
Long: `Manage the visual theme for the Crush TUI interface.`,
14+
}
15+
16+
var themeListCmd = &cobra.Command{
17+
Use: "list",
18+
Short: "List available themes",
19+
Long: `List all available themes for the Crush TUI interface.`,
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
fmt.Println("Available themes:")
22+
fmt.Println(" charmtone - Dark theme (default)")
23+
fmt.Println(" charmtone-light - Light theme")
24+
return nil
25+
},
26+
}
27+
28+
var themeSetCmd = &cobra.Command{
29+
Use: "set [theme-name]",
30+
Short: "Set the current theme",
31+
Long: `Set the theme for the Crush TUI interface. Available themes: charmtone, charmtone-light`,
32+
Args: cobra.ExactArgs(1),
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
themeName := args[0]
35+
36+
// Validate theme name
37+
validThemes := map[string]bool{
38+
"charmtone": true,
39+
"charmtone-light": true,
40+
}
41+
42+
if !validThemes[themeName] {
43+
return fmt.Errorf("invalid theme '%s'. Available themes: charmtone, charmtone-light", themeName)
44+
}
45+
46+
// Load current config
47+
cwd, err := ResolveCwd(cmd)
48+
if err != nil {
49+
return err
50+
}
51+
52+
dataDir, _ := cmd.Flags().GetString("data-dir")
53+
debug, _ := cmd.Flags().GetBool("debug")
54+
55+
cfg, err := config.Init(cwd, dataDir, debug)
56+
if err != nil {
57+
return fmt.Errorf("failed to load config: %w", err)
58+
}
59+
60+
// Set the theme
61+
if err := cfg.SetTheme(themeName); err != nil {
62+
return fmt.Errorf("failed to set theme: %w", err)
63+
}
64+
65+
fmt.Printf("Theme set to '%s'\n", themeName)
66+
return nil
67+
},
68+
}
69+
70+
var themeCurrentCmd = &cobra.Command{
71+
Use: "current",
72+
Short: "Show the current theme",
73+
Long: `Display the currently configured theme for the Crush TUI interface.`,
74+
RunE: func(cmd *cobra.Command, args []string) error {
75+
// Load current config
76+
cwd, err := ResolveCwd(cmd)
77+
if err != nil {
78+
return err
79+
}
80+
81+
dataDir, _ := cmd.Flags().GetString("data-dir")
82+
debug, _ := cmd.Flags().GetBool("debug")
83+
84+
cfg, err := config.Init(cwd, dataDir, debug)
85+
if err != nil {
86+
return fmt.Errorf("failed to load config: %w", err)
87+
}
88+
89+
currentTheme := cfg.GetTheme()
90+
fmt.Printf("Current theme: %s\n", currentTheme)
91+
return nil
92+
},
93+
}
94+
95+
func init() {
96+
themeCmd.AddCommand(themeListCmd)
97+
themeCmd.AddCommand(themeSetCmd)
98+
themeCmd.AddCommand(themeCurrentCmd)
99+
rootCmd.AddCommand(themeCmd)
100+
}

0 commit comments

Comments
 (0)