1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

Merge pull request #1943 from fumiama/title

feat: 在启动时设置标题为 `go-cqhttp 版本 版权`
This commit is contained in:
Mrs4s 2023-03-05 18:01:00 +08:00 committed by GitHub
commit 95adb403e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

15
global/terminal/title.go Normal file
View File

@ -0,0 +1,15 @@
//go:build !windows
package terminal
import (
"fmt"
"time"
"github.com/Mrs4s/go-cqhttp/internal/base"
)
// SetTitle 设置标题为 go-cqhttp `版本` `版权`
func SetTitle() {
fmt.Printf("\033]0;go-cqhttp "+base.Version+" © 2020 - %d Mrs4s"+"\007", time.Now().Year())
}

View File

@ -0,0 +1,29 @@
package terminal
import (
"fmt"
"syscall"
"time"
"unsafe"
"golang.org/x/sys/windows"
"github.com/Mrs4s/go-cqhttp/internal/base"
)
func setConsoleTitle(title string) error {
p0, err := syscall.UTF16PtrFromString(title)
if err != nil {
return err
}
r1, _, err := windows.NewLazySystemDLL("kernel32.dll").NewProc("SetConsoleTitleW").Call(uintptr(unsafe.Pointer(p0)))
if r1 == 0 {
return err
}
return nil
}
// SetTitle 设置标题为 go-cqhttp `版本` `版权`
func SetTitle() {
_ = setConsoleTitle(fmt.Sprintf("go-cqhttp "+base.Version+" © 2020 - %d Mrs4s", time.Now().Year()))
}

View File

@ -14,6 +14,7 @@ import (
) )
func main() { func main() {
terminal.SetTitle()
gocq.InitBase() gocq.InitBase()
gocq.PrepareData() gocq.PrepareData()
gocq.LoginInteract() gocq.LoginInteract()