- Add Go TUI with bubbletea for WireGuard management - Implement client CRUD operations with QR code generation - Add configuration and validation modules - Install/update scripts for client setup - Update Makefile to build binaries to bin/ directory - Add .gitignore for Go projects
90 lines
1.7 KiB
Go
90 lines
1.7 KiB
Go
package screens
|
|
|
|
import (
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
// Screen represents a UI screen (list, add, detail, etc.)
|
|
type Screen interface {
|
|
Init() tea.Cmd
|
|
Update(tea.Msg) (Screen, tea.Cmd)
|
|
View() string
|
|
}
|
|
|
|
// Model is shared state across all screens
|
|
type Model struct {
|
|
err error
|
|
isQuitting bool
|
|
ready bool
|
|
statusMessage string
|
|
screen Screen
|
|
}
|
|
|
|
// View renders the model (implements Screen interface)
|
|
func (m *Model) View() string {
|
|
if m.err != nil {
|
|
return "\n" + lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("196")).
|
|
Render(m.err.Error())
|
|
}
|
|
|
|
if m.isQuitting {
|
|
return "\nGoodbye!\n"
|
|
}
|
|
|
|
if m.screen != nil {
|
|
return m.screen.View()
|
|
}
|
|
|
|
return "Initializing..."
|
|
}
|
|
|
|
// Init initializes the model
|
|
func (m *Model) Init() tea.Cmd {
|
|
m.ready = true
|
|
return nil
|
|
}
|
|
|
|
// Update handles incoming messages (implements Screen interface)
|
|
func (m *Model) Update(msg tea.Msg) (Screen, tea.Cmd) {
|
|
// If we have an error, let it persist for display
|
|
if m.err != nil {
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
if msg.String() == "q" || msg.String() == "ctrl+c" {
|
|
m.isQuitting = true
|
|
return m, tea.Quit
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// No error - handle normally
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "q", "ctrl+c":
|
|
m.isQuitting = true
|
|
return m, tea.Quit
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// SetScreen changes the current screen
|
|
func (m *Model) SetScreen(screen Screen) {
|
|
m.screen = screen
|
|
}
|
|
|
|
// SetError sets an error message
|
|
func (m *Model) SetError(err error) {
|
|
m.err = err
|
|
}
|
|
|
|
// ClearError clears the error message
|
|
func (m *Model) ClearError() {
|
|
m.err = nil
|
|
}
|