dongnanman9093
dongnanman9093
2019-09-04 07:46
浏览 173

在终端中向上/向下/向左/向右移动的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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

相关推荐