mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
feat: 禁用快速编辑&优化启动流程
This commit is contained in:
parent
72173337ae
commit
ddd52ca933
@ -41,8 +41,10 @@ var allowStatus = [...]client.UserOnlineStatus{
|
||||
client.StatusGaming, client.StatusVacationing, client.StatusWatchingTV, client.StatusFitness,
|
||||
}
|
||||
|
||||
// Main 启动主程序
|
||||
func Main() {
|
||||
// InitBase 解析参数并检测
|
||||
//
|
||||
// 如果在 windows 下双击打开了程序,程序将在此函数释出脚本后终止
|
||||
func InitBase() {
|
||||
base.Parse()
|
||||
if !base.FastStart && terminal.RunningByDoubleClick() {
|
||||
err := terminal.NoMoreDoubleClick()
|
||||
@ -50,7 +52,7 @@ func Main() {
|
||||
log.Errorf("遇到错误: %v", err)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return
|
||||
os.Exit(0)
|
||||
}
|
||||
switch {
|
||||
case base.LittleH:
|
||||
@ -65,7 +67,10 @@ func Main() {
|
||||
}
|
||||
}
|
||||
base.Init()
|
||||
}
|
||||
|
||||
// Main 启动主程序,必须在 InitBase 之后执行
|
||||
func Main() {
|
||||
rotateOptions := []rotatelogs.Option{
|
||||
rotatelogs.WithRotationTime(time.Hour * 24),
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
// Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp的函数
|
||||
// Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp, 禁用快速编辑, 启用VT100的函数
|
||||
package terminal
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package terminal
|
||||
|
||||
// RunningByDoubleClick 检查是否通过双击直接运行,非Windows系统永远返回false
|
||||
// RunningByDoubleClick 检查是否通过双击直接运行,非Windows系统永远返回false
|
||||
func RunningByDoubleClick() bool {
|
||||
return false
|
||||
}
|
||||
|
6
global/terminal/quick_edit.go
Normal file
6
global/terminal/quick_edit.go
Normal file
@ -0,0 +1,6 @@
|
||||
package terminal
|
||||
|
||||
// DisableQuickEdit 禁用快速编辑,非Windows系统永远返回nil
|
||||
func DisableQuickEdit() error {
|
||||
return nil
|
||||
}
|
19
global/terminal/quick_edit_windows.go
Normal file
19
global/terminal/quick_edit_windows.go
Normal file
@ -0,0 +1,19 @@
|
||||
package terminal
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// DisableQuickEdit 禁用快速编辑
|
||||
func DisableQuickEdit() error {
|
||||
stdin := windows.Handle(os.Stdin.Fd())
|
||||
|
||||
var mode uint32
|
||||
err := windows.GetConsoleMode(stdin, &mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式
|
||||
mode |= windows.ENABLE_EXTENDED_FLAGS // 启用扩展标志
|
||||
|
||||
return windows.SetConsoleMode(stdin, mode)
|
||||
}
|
6
global/terminal/vt100.go
Normal file
6
global/terminal/vt100.go
Normal file
@ -0,0 +1,6 @@
|
||||
package terminal
|
||||
|
||||
// EnableVT100 启用颜色、控制字符,非Windows系统永远返回nil
|
||||
func EnableVT100() error {
|
||||
return nil
|
||||
}
|
19
global/terminal/vt100_windows.go
Normal file
19
global/terminal/vt100_windows.go
Normal file
@ -0,0 +1,19 @@
|
||||
package terminal
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// EnableVT100 启用颜色、控制字符
|
||||
func EnableVT100() error {
|
||||
stdout := windows.Handle(os.Stdout.Fd())
|
||||
|
||||
var mode uint32
|
||||
err := windows.GetConsoleMode(stdout, &mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING // 启用虚拟终端处理
|
||||
mode |= windows.ENABLE_PROCESSED_OUTPUT // 启用处理后的输出
|
||||
|
||||
return windows.SetConsoleMode(stdout, mode)
|
||||
}
|
4
main.go
4
main.go
@ -3,6 +3,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/Mrs4s/go-cqhttp/cmd/gocq"
|
||||
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||
|
||||
_ "github.com/Mrs4s/go-cqhttp/db/leveldb" // leveldb 数据库支持
|
||||
_ "github.com/Mrs4s/go-cqhttp/modules/silk" // silk编码模块
|
||||
@ -13,5 +14,8 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
gocq.InitBase()
|
||||
terminal.DisableQuickEdit()
|
||||
terminal.EnableVT100()
|
||||
gocq.Main()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user