Skip to content

Commit

Permalink
feat: 在启动时设置标题为 go-cqhttp 版本 版权
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Mar 2, 2023
1 parent c24aa8d commit c3840a5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions global/terminal/title.go
@@ -0,0 +1,15 @@
//go:build !windows

package terminal

import (
"fmt"
"time"

"github.com/Mrs4s/go-cqhttp/internal/base"
)

func init() {
// 设置标题
fmt.Printf("\033]0;go-cqhttp "+base.Version+" © 2020 - %d Mrs4s"+"\007", time.Now().Year())
}
38 changes: 38 additions & 0 deletions global/terminal/title_windows.go
@@ -0,0 +1,38 @@
package terminal

import (
"fmt"
"syscall"
"time"
"unsafe"

"golang.org/x/sys/windows"

"github.com/Mrs4s/go-cqhttp/internal/base"
)

var (
//go:linkname modkernel32 golang.org/x/sys/windows.modkernel32
modkernel32 *windows.LazyDLL
procSetConsoleTitle = modkernel32.NewProc("SetConsoleTitleW")
)

//go:linkname errnoErr golang.org/x/sys/windows.errnoErr
func errnoErr(e syscall.Errno) error

func setConsoleTitle(title string) (err error) {
var p0 *uint16
p0, err = syscall.UTF16PtrFromString(title)
if err != nil {
return
}
r1, _, e1 := syscall.Syscall(procSetConsoleTitle.Addr(), 1, uintptr(unsafe.Pointer(p0)), 0, 0)
if r1 == 0 {
err = errnoErr(e1)
}
return
}

func init() {
_ = setConsoleTitle(fmt.Sprintf("go-cqhttp "+base.Version+" © 2020 - %d Mrs4s", time.Now().Year()))
}

2 comments on commit c3840a5

@kevinshen2014
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢大佬,这个新增功能对区分cmd窗口提供了帮助。
我遇到的困难是:在两个不同目录运行的时候,怎么区分这两个窗口?(有时候只需要关闭/重启其中的一个)
不知道能否:
1)加个自定义别名设置(比如设置了aaa就在标题中多显示aaa);
2)或者显示上1级目录名称(比如在ai01/go-cqhttp/go-cqhttp_windows_amd64.exe运行时,标题多显示ai01);
3)或者直接显示exe文件名也行(这样我可以把go-cqhttp_windows_amd64.exe改名成go-cqhttp_ai01.exe后再运行)。

再次感谢本项目的各位大佬

@Ink-33
Copy link
Contributor

@Ink-33 Ink-33 commented on c3840a5 Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢大佬,这个新增功能对区分cmd窗口提供了帮助。 我遇到的困难是:在两个不同目录运行的时候,怎么区分这两个窗口?(有时候只需要关闭/重启其中的一个) 不知道能否: 1)加个自定义别名设置(比如设置了aaa就在标题中多显示aaa); 2)或者显示上1级目录名称(比如在ai01/go-cqhttp/go-cqhttp_windows_amd64.exe运行时,标题多显示ai01); 3)或者直接显示exe文件名也行(这样我可以把go-cqhttp_windows_amd64.exe改名成go-cqhttp_ai01.exe后再运行)。

再次感谢本项目的各位大佬

可以,好提议

Please sign in to comment.