Working on adding a TUI

This commit is contained in:
2026-01-14 02:18:47 -07:00
parent b2c534f29b
commit 86ccf302ea
6 changed files with 213 additions and 11 deletions

100
model.mm.go Normal file
View File

@@ -0,0 +1,100 @@
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
mmStyle = lipgloss.NewStyle().Margin(1, 2)
selectStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("10")).Bold(true)
unslectStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Italic(true)
quitStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("1")).Faint(true)
)
type mmModel struct {
choices []string
cursor int
selected string
}
func initialmmModel() mmModel {
return mmModel{
choices: []string{"Start server", "Stop server", "Backup saves", "Backup server files", "Enable/Disable mods"},
}
}
func (m mmModel) Init() tea.Cmd { return nil }
func (m mmModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+C", "q":
return m, tea.Quit
case "up", "k":
if m.cursor > 0 {
m.cursor--
}
case "down", "j":
if m.cursor < len(m.choices)-1 {
m.cursor++
}
case "enter":
m.selected = m.choices[m.cursor]
if m.selected == "Quit" {
return m, tea.Quit
}
case "esc":
m.selected = ""
}
}
return m, nil
}
func (m mmModel) View() string {
s := "Would you like to...\n"
for i, choice := range m.choices {
s += "\n"
if m.cursor == i {
s += selectStyle.Render(fmt.Sprintf("◉ [ %s ]", choice))
} else {
s += unslectStyle.Render(fmt.Sprintf("◯ %s ", choice))
}
}
qHint := "Press q to quit."
if m.selected != "" {
s += "\n"
if m.selected == "Start server" {
s += selectStyle.Render("\nstarting server")
mmChouice = "start"
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
}
if m.selected == "Stop server" {
s += selectStyle.Render("\nStopping server")
mmChouice = "stop"
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
}
if m.selected == "Backup saves" {
s += selectStyle.Render("\nBacking up save directory")
mmChouice = "saves"
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
}
if m.selected == "Backup server files" {
s += selectStyle.Render("\nBacking up server files")
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
}
if m.selected == "Enable/Disable mods" {
s += selectStyle.Render("\nnot yet implemented")
s += quitStyle.Render(fmt.Sprintf("\n%s\n", qHint))
}
} else {
s += quitStyle.Render(fmt.Sprintf("\n\n\n%s\n", qHint))
}
return mmStyle.Render(s)
}