Ruby gem command line application: creating a new session in bash

会有一股神秘感。 提交于 2019-12-25 16:36:10

问题


I'm trying to make my command line game to enter its own session (I don't know what the name is, but it looks like this) in bash:

My first attempt looks like this:
To accomplish the above, I use:
system('clear')
and escape key \r\e to rewrite lines above the cursor current position:
print "\r\e[#{lines}A"

What I want is when the command line application exits, the terminal change back to its previous state as if nothing happened, just like using nano, less, and many other command line tools.

How do you make a command line application do that with ruby?


回答1:


I think you're a looking for rmcup and smcup terminal capabilities.

print `tput smcup`
system('clear')
puts 'We are on alternate buffer'
puts 'press enter to switch back'
gets
print `tput rmcup`

You might also want to check "Why doesn't the screen clear when running vi?"



来源:https://stackoverflow.com/questions/31845890/ruby-gem-command-line-application-creating-a-new-session-in-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!