From d85865825e2aebe7fbb0de2ec53697d66fc03527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:29:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96windows=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_windows.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main_windows.go b/main_windows.go index ac4d1f38..4fdd5f25 100644 --- a/main_windows.go +++ b/main_windows.go @@ -5,9 +5,28 @@ import ( "strings" "github.com/sirupsen/logrus" + "golang.org/x/sys/windows" ) func init() { + k32 := windows.NewLazySystemDLL("kernel32.dll") + getstdhandle := k32.NewProc("GetStdHandle") + h, _, err := getstdhandle.Call(uintptr(0xffffffff_fffffff6)) // STD_INPUT_HANDLE = ((DWORD)-10) + if int(h) == 0 || int(h) == -1 { + panic(err) + } + h, _, err = k32.NewProc("SetConsoleMode").Call(h, uintptr(0x02a7)) // 禁用快速编辑 + if h == 0 { + panic(err) + } + h, _, err = getstdhandle.Call(uintptr(0xffffffff_fffffff5)) // STD_OUTPUT_HANDLE = ((DWORD)-11) + if int(h) == 0 || int(h) == -1 { + panic(err) + } + h, _, err = k32.NewProc("SetConsoleMode").Call(h, uintptr(0x001f)) // 启用VT100 + if h == 0 { + panic(err) + } // windows 带颜色 log 自定义格式 logrus.SetFormatter(&LogFormat{}) }