hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/commands.go
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-29 02:51:16 +0200
committerhachem <im@hachem.wtf>2026-08-29 02:51:16 +0200
commitf60177934a18daea3b24a37cf109bb2c7bfaaa72 (patch)
tree7b6e20dd7b5c94b9c176e75497c5045dcb589075 /internal/cli/commands.go
parente56d21fa04450d118f76347a96a12d1d5477958f (diff)
feat: nicer ui
Diffstat (limited to 'internal/cli/commands.go')
-rw-r--r--internal/cli/commands.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/internal/cli/commands.go b/internal/cli/commands.go
new file mode 100644
index 0000000..1f1f132
--- /dev/null
+++ b/internal/cli/commands.go
@@ -0,0 +1,77 @@
+package cli
+
+import (
+ "fmt"
+ "strings"
+
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
+
+ "github.com/hachem-wtf/benson/internal/config"
+)
+
+func defaultCommands() []command {
+ return []command{
+ {
+ name: "list-mods",
+ desc: "List the configured mods",
+ run: func(m *model) tea.Cmd {
+ return tea.Println(renderModList(m.cfg))
+ },
+ },
+ {
+ name: "help",
+ desc: "Show available commands",
+ run: func(m *model) tea.Cmd {
+ return tea.Println(helpBlock(m.commands))
+ },
+ },
+ }
+}
+
+func welcomeBlock(cfg *config.Config, version string) string {
+ inner := lipgloss.JoinVertical(
+ lipgloss.Left,
+ titleStyle.Render("BENSON"),
+ subtitleStyle.Render("a Minecraft server manager from hell"),
+ "",
+ mutedStyle.Render(fmt.Sprintf("Fabric · MC %s · v%s", cfg.MinecraftVersion, version)),
+ )
+
+ hint := mutedStyle.Render("Type a command below. Tab autocompletes · Ctrl+C quits.")
+
+ return lipgloss.JoinVertical(lipgloss.Left, bannerStyle.Render(inner), "", hint)
+}
+
+func helpBlock(cmds []command) string {
+ rows := []string{headingStyle.Render("Commands"), ""}
+ for _, c := range cmds {
+ rows = append(rows, " "+bulletStyle.Render(padRight(c.name, 14))+mutedStyle.Render(c.desc))
+ }
+ rows = append(rows, " "+bulletStyle.Render(padRight("exit", 14))+mutedStyle.Render("Exit Benson"))
+ return lipgloss.JoinVertical(lipgloss.Left, rows...)
+}
+
+func renderModList(cfg *config.Config) string {
+ rows := []string{
+ headingStyle.Render(fmt.Sprintf("Mods for MC %s", cfg.MinecraftVersion)),
+ "",
+ }
+
+ if len(cfg.ModrinthMods) == 0 {
+ rows = append(rows, mutedStyle.Render(" (none configured)"))
+ }
+ for _, slug := range cfg.ModrinthMods {
+ rows = append(rows, " "+bulletStyle.Render("◆ ")+slug)
+ }
+
+ rows = append(rows, "", mutedStyle.Render(fmt.Sprintf("Total: %d mods", len(cfg.ModrinthMods))))
+ return lipgloss.JoinVertical(lipgloss.Left, rows...)
+}
+
+func padRight(s string, n int) string {
+ if pad := n - len([]rune(s)); pad > 0 {
+ return s + strings.Repeat(" ", pad)
+ }
+ return s
+}