98dfc1c79c
- pkg/tui/session.go — SessionTab with live SSH terminal in a tab - pkg/tui/messages.go — quitMsg, openSessionMsg, sessionOutputMsg - pkg/tui/tabs.go — Tab.Close() interface, Add() returns tea.Cmd - pkg/tui/host_list_tab.go — Enter opens session tab, q quits - pkg/tui/tui.go — handle openSessionMsg/quitMsg, SetDataDir - cmd/hostkeeper/tui.go — pass dataDir to model
59 lines
1.2 KiB
Go
59 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.SetDataDir(cfg.GetDataDir())
|
|
model.LoadHosts(hosts)
|
|
|
|
p := tea.NewProgram(model)
|
|
if _, err := p.Run(); err != nil {
|
|
return fmt.Errorf("failed to run TUI: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|