0
我想制作一个看起来像top
或类似的程序,它可以在运行时更新几行代码。在Mac OS Terminal.app中的system "clear"
实际上只是将当前内容滚动到顶端,所以如果我向上滚动,我会看到很多垃圾。
这是可以通过curses
解决,但不是矫枉过正?运行时刷新控制台中的几行
我想制作一个看起来像top
或类似的程序,它可以在运行时更新几行代码。在Mac OS Terminal.app中的system "clear"
实际上只是将当前内容滚动到顶端,所以如果我向上滚动,我会看到很多垃圾。
这是可以通过curses
解决,但不是矫枉过正?运行时刷新控制台中的几行
你正在尝试做什么被称为'替代屏幕'。
如果你认为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"
要删除以前的文字:
我想'curses'是不是矫枉过正,但标准的方式。毕竟2.1是在2.1之前的ruby core lib。 – halfelf