Ruby gem 命令行应用程序:在 bash 中创建一个新会话

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

我正在尝试让我的命令行游戏在 bash:
中进入它自己的会话(我不知道名字是什么,但它看起来像这样)

我的第一次尝试是这样的:
为了实现上述目标,我使用:
system('clear')
和转义键 \r\e 重写光标当前位置上方的行:
print "\r\e[#{lines}A"

我想要的是当命令行应用程序退出时,终端变回之前的状态,就好像什么都没发生一样,就像使用nanoless和许多其他命令行工具一样.

如何让命令行应用程序使用 ruby 执行此操作?

我认为您正在寻找 rmcupsmcup 终端功能。

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

您可能还想查看 "Why doesn't the screen clear when running vi?"