Skip to content

Commit

Permalink
优化windows输出
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Feb 28, 2023
1 parent 2704d3e commit d858658
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand Down

0 comments on commit d858658

Please sign in to comment.