diff --git a/internal/config/config.go b/internal/config/config.go index 13f27af..d465872 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,6 +4,7 @@ package config import ( "fmt" "os" + "strings" "time" ) @@ -28,6 +29,15 @@ type Config struct { HotkeyMod string } +// NormalizeHotkey validates and normalizes a hotkey modifier string. +func NormalizeHotkey(mod string) string { + mod = strings.ToLower(strings.TrimSpace(mod)) + if mod != "ctrl+alt" && mod != "ctrl+shift" { + mod = "ctrl+alt" + } + return mod +} + // OpenLogFile opens the configured log file for writing, or returns nil if logging is disabled. func OpenLogFile(cfg *Config) (*os.File, error) { if cfg.EnableLog { diff --git a/internal/console/console.go b/internal/console/console.go index dd4f521..e122db1 100644 --- a/internal/console/console.go +++ b/internal/console/console.go @@ -66,6 +66,7 @@ func Run() { if cfg.EnableGUI { model := tui.New(appInst) p := tea.NewProgram(model, tea.WithAltScreen(), tea.WithoutSignalHandler()) + enableVTInput(int(os.Stdin.Fd())) // Restore VT input for Ctrl+Alt+Key hotkeys if _, err = p.Run(); err != nil { fmt.Fprintf(os.Stderr, "tui failed: %v\n", err) os.Exit(1) @@ -336,13 +337,7 @@ func isExitHotkeySeq(seq []byte, cfg *config.Config) bool { return false } -func normalizeHotkey(mod string) string { - mod = strings.ToLower(strings.TrimSpace(mod)) - if mod != "ctrl+alt" && mod != "ctrl+shift" { - mod = "ctrl+alt" - } - return mod -} +func normalizeHotkey(mod string) string { return config.NormalizeHotkey(mod) } func echoConsoleByte(out io.Writer, b byte) { _, _ = out.Write([]byte{b}) } func echoConsoleNewline(out io.Writer) { _, _ = io.WriteString(out, "\r\n") } diff --git a/internal/tui/hotkeys.go b/internal/tui/hotkeys.go index 7ba633c..ef24c5d 100644 --- a/internal/tui/hotkeys.go +++ b/internal/tui/hotkeys.go @@ -4,6 +4,7 @@ import ( "strings" tea "github.com/charmbracelet/bubbletea" + "github.com/jixishi/SerialTerminalForWindowsTerminal/internal/config" "github.com/jixishi/SerialTerminalForWindowsTerminal/internal/event" ) @@ -55,13 +56,7 @@ func (m *Model) isLocalHotkey(key, action string) bool { return hasCtrl && hasAlt } -func normalizeHotkeyPrefix(mod string) string { - mod = strings.ToLower(strings.TrimSpace(mod)) - if mod != "ctrl+alt" && mod != "ctrl+shift" { - mod = "ctrl+alt" - } - return mod -} +func normalizeHotkeyPrefix(mod string) string { return config.NormalizeHotkey(mod) } func hotkeyWith(mod, action string) string { return normalizeHotkeyPrefix(mod) + "+" + action