mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2026-03-14 03:41:27 +01:00
Hosts tagged with "hidden" are excluded from the TUI list, shell completions, and sshm search. Direct connections via sshm <host> still work regardless of the tag. A toggle key (H) shows or hides hidden hosts in the TUI, with a yellow banner indicating the active state. The key is documented in the help panel (h). A contextual hint on the Tags field in the add and edit forms reminds the user that "hidden" hides the host from the list.
144 lines
3.3 KiB
Go
144 lines
3.3 KiB
Go
package ui
|
|
|
|
import (
|
|
"github.com/Gu1llaum-3/sshm/internal/config"
|
|
"github.com/Gu1llaum-3/sshm/internal/connectivity"
|
|
"github.com/Gu1llaum-3/sshm/internal/history"
|
|
"github.com/Gu1llaum-3/sshm/internal/version"
|
|
|
|
"github.com/charmbracelet/bubbles/table"
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
// SortMode defines the available sorting modes
|
|
type SortMode int
|
|
|
|
const (
|
|
SortByName SortMode = iota
|
|
SortByLastUsed
|
|
)
|
|
|
|
func (s SortMode) String() string {
|
|
switch s {
|
|
case SortByName:
|
|
return "Name (A-Z)"
|
|
case SortByLastUsed:
|
|
return "Last Login"
|
|
default:
|
|
return "Name (A-Z)"
|
|
}
|
|
}
|
|
|
|
// ViewMode defines the current view state
|
|
type ViewMode int
|
|
|
|
const (
|
|
ViewList ViewMode = iota
|
|
ViewAdd
|
|
ViewEdit
|
|
ViewMove
|
|
ViewInfo
|
|
ViewPortForward
|
|
ViewHelp
|
|
ViewFileSelector
|
|
)
|
|
|
|
// PortForwardType defines the type of port forwarding
|
|
type PortForwardType int
|
|
|
|
const (
|
|
LocalForward PortForwardType = iota
|
|
RemoteForward
|
|
DynamicForward
|
|
)
|
|
|
|
func (p PortForwardType) String() string {
|
|
switch p {
|
|
case LocalForward:
|
|
return "Local (-L)"
|
|
case RemoteForward:
|
|
return "Remote (-R)"
|
|
case DynamicForward:
|
|
return "Dynamic (-D)"
|
|
default:
|
|
return "Local (-L)"
|
|
}
|
|
}
|
|
|
|
// Model represents the state of the user interface
|
|
type Model struct {
|
|
table table.Model
|
|
searchInput textinput.Model
|
|
allHosts []config.SSHHost // all parsed hosts, including hidden ones
|
|
hosts []config.SSHHost // visible hosts (filtered by showHidden)
|
|
filteredHosts []config.SSHHost
|
|
showHidden bool // when true, hidden-tagged hosts are shown
|
|
searchMode bool
|
|
deleteMode bool
|
|
deleteHost *config.SSHHost // Host to be deleted (with line number for precise targeting)
|
|
historyManager *history.HistoryManager
|
|
pingManager *connectivity.PingManager
|
|
sortMode SortMode
|
|
configFile string // Path to the SSH config file
|
|
|
|
// Application configuration
|
|
appConfig *config.AppConfig
|
|
|
|
// Version update information
|
|
updateInfo *version.UpdateInfo
|
|
currentVersion string
|
|
|
|
// View management
|
|
viewMode ViewMode
|
|
addForm *addFormModel
|
|
editForm *editFormModel
|
|
moveForm *moveFormModel
|
|
infoForm *infoFormModel
|
|
portForwardForm *portForwardModel
|
|
helpForm *helpModel
|
|
fileSelectorForm *fileSelectorModel
|
|
|
|
// Terminal size and styles
|
|
width int
|
|
height int
|
|
styles Styles
|
|
ready bool
|
|
|
|
// Error handling
|
|
errorMessage string
|
|
showingError bool
|
|
}
|
|
|
|
// applyVisibilityFilter returns hosts filtered according to the showHidden flag.
|
|
func (m Model) applyVisibilityFilter(hosts []config.SSHHost) []config.SSHHost {
|
|
if m.showHidden {
|
|
return hosts
|
|
}
|
|
return config.FilterVisibleHosts(hosts)
|
|
}
|
|
|
|
// updateTableStyles updates the table header border color based on focus state
|
|
func (m *Model) updateTableStyles() {
|
|
s := table.DefaultStyles()
|
|
s.Selected = m.styles.Selected
|
|
|
|
if m.searchMode {
|
|
// When in search mode, use secondary color for table header
|
|
s.Header = s.Header.
|
|
BorderStyle(lipgloss.NormalBorder()).
|
|
BorderForeground(lipgloss.Color(SecondaryColor)).
|
|
BorderBottom(true).
|
|
Bold(false)
|
|
} else {
|
|
// When table is focused, use primary color for table header
|
|
s.Header = s.Header.
|
|
BorderStyle(lipgloss.NormalBorder()).
|
|
BorderForeground(lipgloss.Color(PrimaryColor)).
|
|
BorderBottom(true).
|
|
Bold(false)
|
|
}
|
|
|
|
m.table.SetStyles(s)
|
|
}
|