Merge pull request #11 from qingfengzxr/main

feat: add configurable key bindings with ESC quit disable option
This commit is contained in:
Guillaume Archambault
2025-10-04 17:00:56 +02:00
committed by GitHub
6 changed files with 416 additions and 3 deletions

View File

@@ -80,6 +80,9 @@ type Model struct {
sortMode SortMode
configFile string // Path to the SSH config file
// Application configuration
appConfig *config.AppConfig
// Version update information
updateInfo *version.UpdateInfo
currentVersion string

View File

@@ -17,6 +17,15 @@ import (
// NewModel creates a new TUI model with the given SSH hosts
func NewModel(hosts []config.SSHHost, configFile, currentVersion string) Model {
// Load application configuration
appConfig, err := config.LoadAppConfig()
if err != nil {
// Log the error but continue with default configuration
fmt.Printf("Warning: Could not load application config: %v, using defaults\n", err)
defaultConfig := config.GetDefaultAppConfig()
appConfig = &defaultConfig
}
// Initialize the history manager
historyManager, err := history.NewHistoryManager()
if err != nil {
@@ -39,6 +48,7 @@ func NewModel(hosts []config.SSHHost, configFile, currentVersion string) Model {
sortMode: SortByName,
configFile: configFile,
currentVersion: currentVersion,
appConfig: appConfig,
styles: styles,
width: 80,
height: 24,

View File

@@ -445,8 +445,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
key := msg.String()
switch msg.String() {
switch key {
case "esc", "ctrl+c":
if m.deleteMode {
// Exit delete mode
@@ -455,10 +456,16 @@ func (m Model) handleListViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.table.Focus()
return m, nil
}
return m, tea.Quit
// Use configurable key bindings for quit
if m.appConfig != nil && m.appConfig.KeyBindings.ShouldQuitOnKey(key) {
return m, tea.Quit
}
case "q":
if !m.searchMode && !m.deleteMode {
return m, tea.Quit
// Use configurable key bindings for quit
if m.appConfig != nil && m.appConfig.KeyBindings.ShouldQuitOnKey(key) {
return m, tea.Quit
}
}
case "/", "ctrl+f":
if !m.searchMode && !m.deleteMode {