2015-09-02 29 views
0

我想製作一個看起來像top或類似的程序,它可以在運行時更新幾行代碼。在Mac OS Terminal.app中的system "clear"實際上只是將當前內容滾動到頂端,所以如果我向上滾動,我會看到很多垃圾。
這是可以通過curses解決,但不是矯枉過正?運行時刷新控制檯中的幾行

+0

我想'curses'是不是矯枉過正,但標準的方式。畢竟2.1是在2.1之前的ruby core lib。 – halfelf

回答

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" 

要刪除以前的文字:

​​