我想创建一个类似于top
的程序或类似的程序,在运行时更新多行。 Mac OS Terminal.app中的system "clear"
实际上只是将当前内容滚动到顶部,所以如果我向上滚动,我会看到很多垃圾。
它可以通过curses
以某种方式解决,但是它不会过度杀伤吗?
答案 0 :(得分:1)
您要制作的内容称为'备用屏幕'
如果您认为curses
对此有些过分,那么也许您可以执行已经提供给我here的解决方案。
print `tput smcup`
puts 'We are on alternate screen'
# ...do something here...
# when you finished, do this to get out of the alternate screen
print `tput rmcup`
要重写几行:
print "\r\e[#{number_of_lines_to_jump_up_to}A"
删除以前的字符:
print "\b"*number_of_characters_to_delete # \b for backspace