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

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素