diff --git a/global/terminal/quick_edit.go b/global/terminal/quick_edit.go index afa6b4c..1ed25e4 100644 --- a/global/terminal/quick_edit.go +++ b/global/terminal/quick_edit.go @@ -2,6 +2,11 @@ package terminal +// RestoreInputMode 还原输入模式,非Windows系统永远返回nil +func RestoreInputMode() error { + return nil +} + // DisableQuickEdit 禁用快速编辑,非Windows系统永远返回nil func DisableQuickEdit() error { return nil diff --git a/global/terminal/quick_edit_windows.go b/global/terminal/quick_edit_windows.go index 3a1dfaa..dbcd9ff 100644 --- a/global/terminal/quick_edit_windows.go +++ b/global/terminal/quick_edit_windows.go @@ -6,6 +6,17 @@ import ( "golang.org/x/sys/windows" ) +var inputmode uint32 + +// RestoreInputMode 还原输入模式 +func RestoreInputMode() error { + if inputmode == 0 { + return nil + } + stdin := windows.Handle(os.Stdin.Fd()) + return windows.SetConsoleMode(stdin, mode) +} + // DisableQuickEdit 禁用快速编辑 func DisableQuickEdit() error { stdin := windows.Handle(os.Stdin.Fd()) @@ -15,6 +26,7 @@ func DisableQuickEdit() error { if err != nil { return err } + inputmode = mode mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式 mode |= windows.ENABLE_EXTENDED_FLAGS // 启用扩展标志 diff --git a/main.go b/main.go index 1c77d8c..90f5b20 100644 --- a/main.go +++ b/main.go @@ -18,4 +18,5 @@ func main() { _ = terminal.DisableQuickEdit() _ = terminal.EnableVT100() gocq.Main() + _ = terminal.RestoreInputMode() }