修改打印行的值

huangapple go评论95阅读模式
英文:

Changing value of printed line

问题

在我的基于命令行界面的Go应用程序中,我需要更新一些已经打印出来的值。我已经找到了一个Stack Overflow的问题,了解到使用\r可以将"输出指针"指向前一行的第一个字符,从而覆盖它。但是多个\r并不起作用...那么我该如何更新已经打印出来的第二行呢?

示例:

#Id    #Name    #pwr    #dB
0      Name     unkn    -34

我希望在不打印新行的情况下更新这些值:

#Id    #Name    #pwr    #dB
0      NewName  45      -34
英文:

in my go-application which is cli-based I Need to update some values which are already printed. I already found a stackoverflow-question where I got to know that with \r the "Output-pointer" points to the first char of the former line, therefore overriding it. But multiple \rs arent working...
So how do I update e.g. the second line I printed.
Example:

#Id    #Name    #pwr    #dB
0      Name     unkn    -34

And I want to update those values without printing new lines

#Id    #Name    #pwr    #dB
0      NewName  45      -34

答案1

得分: 2

除了更改当前行之外,正如你注意到的那样,\r无法起作用。解决方案是将终端设置为允许更多控制的不同模式。然而,手动完成这个过程很麻烦。幸运的是,有一些库可以简化这个过程。其中一个非常著名的库是ncurses

对于Go语言,GoCUI看起来很不错。它应该能够提供你所需的所有功能,并具有良好的界面。

英文:

To do anything more than changing the current line, as you noticed, \r won't work. The solution is to set your terminal in a different mode which allow more control. However, this is painful to do by hand. Luckily, there are libraries out there that makes it easy. A very famous one is ncurses.

For Go, GoCUI looks great. It should give you all the power you need with a nice interface.

huangapple
  • 本文由 发表于 2015年8月18日 00:29:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/32055364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定