Files
HostKeeper/pkg/tui/messages.go
T
swanadiva 94ec00c303 feat: TUI SFTP Browser Tab - Task 18
- SFTPBrowserTab with remote directory browsing
- Open via Ctrl+F from host list
- Navigate dirs, filter with /, refresh with r
- Dir/icon display with file sizes
- Sort dirs first, then by name
2026-06-23 15:08:22 +07:00

72 lines
1.6 KiB
Go

package tui
import (
"context"
tea "github.com/charmbracelet/bubbletea"
"git.tukangketik.id/swanadiva/hostkeeper/internal/models"
"git.tukangketik.id/swanadiva/hostkeeper/pkg/storage"
)
// quitMsg signals the TUI to exit
type quitMsg struct{}
// openSessionMsg signals the TUI to open a new SSH session tab
type openSessionMsg struct {
host *models.Host
}
// sessionOutputMsg carries SSH output to the TUI renderer
type sessionOutputMsg string
// sessionDoneMsg signals that a session has ended
type sessionDoneMsg struct {
err error
}
// openHostFormMsg signals the TUI to open a host form tab
type openHostFormMsg struct {
editing *models.Host // nil for add mode
}
// closeFormMsg signals the TUI to close the active form tab
type closeFormMsg struct{}
// saveHostMsg is produced when the form needs to save a host
type saveHostMsg struct {
host *models.Host
dataDir string
}
// saveHostResultMsg is produced after a save attempt
type saveHostResultMsg struct {
host *models.Host
err error
}
// openSFTPMsg signals the TUI to open an SFTP browser tab
type openSFTPMsg struct {
host *models.Host
}
// loadedHostsMsg is produced after reloading hosts from storage
type loadedHostsMsg struct {
hosts []*models.Host
}
// saveHostCmd creates a command that saves a host to storage
func saveHostCmd(host *models.Host, dataDir string) tea.Cmd {
return func() tea.Msg {
store, err := storage.NewJSONStorage(dataDir)
if err != nil {
return saveHostResultMsg{err: err}
}
ctx := context.Background()
if err := store.SaveHost(ctx, host); err != nil {
return saveHostResultMsg{err: err}
}
return saveHostResultMsg{host: host}
}
}