Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())) | ||
} |
c3840a5
There was a problem hiding this comment.
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后再运行)。
再次感谢本项目的各位大佬
c3840a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以,好提议