在终端中向上/向下/向左/向右移动的Windows方法是什么

I am creating a CLI for an API in Go and I am struggling with displaying the output.

In Linux you can simply print \033[%dA to \033[%dD to move in certain directions, but Powershell and Command Prompt try to print these, leading to

[2K192.168.212.182...successful
[28D[2K192.168.212.28....requested
[27D[2A[2K192.168.212.182...successful
[28D[2K192.168.212.28....successful
[28D

instead of

192.168.212.182...successful
192.168.212.28....successful

The Code for displaying this is the following

for i := 0; i < len(localName); i++ {
    dotc := maxlength - len(localName[i])
    dots := "..."
    for j := 0; j < dotc; j++ {
        dots += "."
    }
    terminal.Stdout.ClearLine().Print(localName[i] + dots + localStatus[i]).Nl().Left(len(localName[i] + dots + localStatus[i]))
}

The function Left(int) simply prints \033[%dD x times

doujin8476
doujin8476 该程序是用Go编写的,因此.netFramework或多或少是不可能的。
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问