fix: reformat code

This commit is contained in:
Gu1llaum-3 2025-09-02 09:21:00 +02:00
parent 01f2b4e6be
commit 1d50e7cb47
2 changed files with 20 additions and 20 deletions

View File

@ -36,7 +36,7 @@ func NewHistoryManager() (*HistoryManager, error) {
} }
historyPath := filepath.Join(homeDir, ".ssh", "sshm_history.json") historyPath := filepath.Join(homeDir, ".ssh", "sshm_history.json")
hm := &HistoryManager{ hm := &HistoryManager{
historyPath: historyPath, historyPath: historyPath,
history: &ConnectionHistory{Connections: make(map[string]ConnectionInfo)}, history: &ConnectionHistory{Connections: make(map[string]ConnectionInfo)},
@ -83,7 +83,7 @@ func (hm *HistoryManager) saveHistory() error {
// RecordConnection records a new connection for the specified host // RecordConnection records a new connection for the specified host
func (hm *HistoryManager) RecordConnection(hostName string) error { func (hm *HistoryManager) RecordConnection(hostName string) error {
now := time.Now() now := time.Now()
if conn, exists := hm.history.Connections[hostName]; exists { if conn, exists := hm.history.Connections[hostName]; exists {
// Update existing connection // Update existing connection
conn.LastConnect = now conn.LastConnect = now
@ -130,7 +130,7 @@ func (hm *HistoryManager) SortHostsByLastUsed(hosts []config.SSHHost) []config.S
if existsI && existsJ { if existsI && existsJ {
return timeI.After(timeJ) return timeI.After(timeJ)
} }
// Hosts with history come before hosts without history // Hosts with history come before hosts without history
if existsI && !existsJ { if existsI && !existsJ {
return true return true
@ -138,7 +138,7 @@ func (hm *HistoryManager) SortHostsByLastUsed(hosts []config.SSHHost) []config.S
if !existsI && existsJ { if !existsI && existsJ {
return false return false
} }
// If neither has history, sort alphabetically // If neither has history, sort alphabetically
return sorted[i].Name < sorted[j].Name return sorted[i].Name < sorted[j].Name
}) })
@ -159,7 +159,7 @@ func (hm *HistoryManager) SortHostsByMostUsed(hosts []config.SSHHost) []config.S
if countI != countJ { if countI != countJ {
return countI > countJ return countI > countJ
} }
// If counts are equal, sort by most recent // If counts are equal, sort by most recent
timeI, existsI := hm.GetLastConnectionTime(sorted[i].Name) timeI, existsI := hm.GetLastConnectionTime(sorted[i].Name)
timeJ, existsJ := hm.GetLastConnectionTime(sorted[j].Name) timeJ, existsJ := hm.GetLastConnectionTime(sorted[j].Name)
@ -167,7 +167,7 @@ func (hm *HistoryManager) SortHostsByMostUsed(hosts []config.SSHHost) []config.S
if existsI && existsJ { if existsI && existsJ {
return timeI.After(timeJ) return timeI.After(timeJ)
} }
// If neither has history, sort alphabetically // If neither has history, sort alphabetically
return sorted[i].Name < sorted[j].Name return sorted[i].Name < sorted[j].Name
}) })

View File

@ -57,17 +57,17 @@ func (s SortMode) String() string {
} }
type Model struct { type Model struct {
table table.Model table table.Model
searchInput textinput.Model searchInput textinput.Model
hosts []config.SSHHost hosts []config.SSHHost
filteredHosts []config.SSHHost filteredHosts []config.SSHHost
searchMode bool searchMode bool
deleteMode bool deleteMode bool
deleteHost string deleteHost string
exitAction string exitAction string
exitHostName string exitHostName string
historyManager *history.HistoryManager historyManager *history.HistoryManager
sortMode SortMode sortMode SortMode
} }
func (m Model) Init() tea.Cmd { func (m Model) Init() tea.Cmd {
@ -157,7 +157,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
selected := m.table.SelectedRow() selected := m.table.SelectedRow()
if len(selected) > 0 { if len(selected) > 0 {
hostName := selected[0] // Host name is in the first column hostName := selected[0] // Host name is in the first column
// Record the connection in history // Record the connection in history
if m.historyManager != nil { if m.historyManager != nil {
err := m.historyManager.RecordConnection(hostName) err := m.historyManager.RecordConnection(hostName)
@ -166,7 +166,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
fmt.Printf("Warning: Could not record connection history: %v\n", err) fmt.Printf("Warning: Could not record connection history: %v\n", err)
} }
} }
return m, tea.ExecProcess(exec.Command("ssh", hostName), func(err error) tea.Msg { return m, tea.ExecProcess(exec.Command("ssh", hostName), func(err error) tea.Msg {
return tea.Quit() return tea.Quit()
}) })
@ -510,7 +510,7 @@ func NewModel(hosts []config.SSHHost) Model {
// Calculate optimal width for the Tags column // Calculate optimal width for the Tags column
tagsWidth := calculateTagsColumnWidth(sortedHosts) tagsWidth := calculateTagsColumnWidth(sortedHosts)
// Calculate optimal width for the Last Login column // Calculate optimal width for the Last Login column
lastLoginWidth := calculateLastLoginColumnWidth(sortedHosts, historyManager) lastLoginWidth := calculateLastLoginColumnWidth(sortedHosts, historyManager)