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 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多
    • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
    • ¥15 有赏,i卡绘世画不出
    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入