Skip to content

Commit

Permalink
feat(cli): Make theme configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed Jul 16, 2024
1 parent 42a0c9d commit ebbb546
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Flags:
Where to install the tools (default ".")
-list
Print all available tools
-theme string
Set theme for interactive mode (default "catppuccin")
-tool value
Specify multiple tools to install programmatically (e.g., -tool kustomize -tool task)
-version
Expand Down
3 changes: 3 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type cliConfig struct {
debug bool
downloadDir string
list bool
theme string
toolList toolList
}
type toolList []string
Expand All @@ -34,6 +35,7 @@ func cli() cliConfig {
accessibleFlag := flag.Bool("accessible", false, "Enable accessibility mode for interactive use")
downloadDirFlag := flag.String("installDir", ".", "Where to install the tools")
listFlag := flag.Bool("list", false, "Print all available tools")
themeFlag := flag.String("theme", "catppuccin", "Set theme for interactive mode")
flag.Var(&toolList, "tool", "Specify multiple tools to install programmatically (e.g., -tool kustomize -tool task)")
flag.Parse()
if *helpFlag {
Expand Down Expand Up @@ -62,5 +64,6 @@ func cli() cliConfig {
if len(toolList) > 0 {
cliFlags.toolList = toolList
}
cliFlags.theme = *themeFlag
return cliFlags
}
29 changes: 20 additions & 9 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ var (
selectedTools []string
)

// TODO: make configurable
var theme = huh.ThemeCatppuccin()

func formatToolString(name string, tool Tool) string {
func formatToolString(theme *huh.Theme, name string, tool Tool) string {

toolNameStyle := lipgloss.NewStyle().
Foreground(theme.Focused.Title.GetForeground())
Expand Down Expand Up @@ -46,24 +43,24 @@ func formatToolString(name string, tool Tool) string {

}

func createToolOptions(tools Tools) []huh.Option[string] {
func createToolOptions(theme *huh.Theme, tools Tools) []huh.Option[string] {
sortedTools := sortTools(tools)
options := make([]huh.Option[string], 0, len(tools.Tools))
for _, name := range sortedTools {
tool := tools.Tools[name]
option := huh.NewOption(formatToolString(name, tool), name)
option := huh.NewOption(formatToolString(theme, name, tool), name)
options = append(options, option)
}
return options
}

func createForm(tools Tools) *huh.Form {
func createForm(theme *huh.Theme, tools Tools) *huh.Form {
form := huh.NewForm(
huh.NewGroup(
huh.NewMultiSelect[string]().
Title("Which tools do you want to install?").
Description("Chose one or more tools to be downloaded.").
Options(createToolOptions(tools)...).
Options(createToolOptions(theme, tools)...).
Validate(func(t []string) error {
if len(t) == 0 {
return errors.New("you must select at least one tool")
Expand Down Expand Up @@ -92,7 +89,21 @@ func processSelectedTools(cfg cliConfig, tools Tools) func() {
}

func startUI(cfg cliConfig, tools Tools) {
form := createForm(tools)
var theme *huh.Theme
switch strings.ToLower(cfg.theme) {
case "base16":
theme = huh.ThemeBase16()
case "catppuccin":
theme = huh.ThemeCatppuccin()
case "charm":
theme = huh.ThemeCharm()
case "dracula":
theme = huh.ThemeDracula()
default:
logger.Warn("unknown theme. valid themes are 'base16', 'catppuccin' (default), 'charm', and 'dracula'")
}

form := createForm(theme, tools)
form.WithAccessible(cfg.accessible)
form.WithTheme(theme)

Expand Down

0 comments on commit ebbb546

Please sign in to comment.