Files
HostKeeper/cmd/hostkeeper/tui.go
T
swanadiva fbe444c3ab feat: implement basic TUI framework with host list
- Add Bubble Tea TUI model with Init/Update/View
- Implement host list screen with keyboard navigation (up/down/enter/q)
- Add styled rendering for hosts, selection, tags
- Create hostkeeper tui CLI command
- Add tests for TUI initialization and host loading
- Update project state documentation
2026-06-23 13:54:49 +07:00

58 lines
1.2 KiB
Go

package main
import (
"context"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/config"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/storage"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/tui"
)
// tuiCmd represents the tui command
var tuiCmd = &cobra.Command{
Use: "tui",
Short: "Launch terminal user interface",
Long: `Launch an interactive terminal user interface for managing SSH hosts and connections.`,
RunE: runTUI,
}
func init() {
rootCmd.AddCommand(tuiCmd)
}
func runTUI(cmd *cobra.Command, args []string) error {
cfg := appCfg
if cfg == nil {
var err error
cfg, err = config.New()
if err != nil {
return fmt.Errorf("failed to initialize config: %w", err)
}
}
store, err := storage.NewJSONStorage(cfg.GetDataDir())
if err != nil {
return fmt.Errorf("failed to initialize storage: %w", err)
}
ctx := context.Background()
hosts, err := store.ListHosts(ctx)
if err != nil {
return fmt.Errorf("failed to load hosts: %w", err)
}
model := tui.New()
model.LoadHosts(hosts)
p := tea.NewProgram(model)
if _, err := p.Run(); err != nil {
return fmt.Errorf("failed to run TUI: %w", err)
}
return nil
}