gocui库地址:https://github.com/jroimartin/gocui
参考地址:https://github.com/jroimartin/gocui/issues/217
func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
if runtime.GOOS == "windows" && runewidth.IsEastAsian() {
g.ASCII = true
}
}
func layout(g *gocui.Gui) error {
//----------此处是添加关键------------
if runtime.GOOS == "windows" && runewidth.IsEastAsian() {
g.ASCII = true
}
//-------------↑↑↑↑↑↑↑↑↑↑----------
maxX, maxY := g.Size()
if v, err := g.SetView("hello", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "Hello 你好!")
}
return nil
}
参考地址:https://blog.csdn.net/yuoveyu/article/details/129042138
通过 go env查看 GOCACHE 保存位置,修改 gocui 源码。
PS D:\go\gocui\hello> go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Administrator\go\pkg\mod //此处是保存位置
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20
set GCCGO=gccgo
修改 view.go 文件。说明:该文件是只读模式,需要修改。
//view.go 旧代码
if err := v.setRune(x, y, c.chr, fgColor, bgColor); err != nil {
return nil, err
}
x++
//x++修改为
x += runewidth.RuneWidth(c.chr)
3.再在view.go中import “github.com/mattn/go-runewidth”