Temporarily clear the terminal in Linux

折月煮酒 提交于 2019-12-12 04:52:44

问题


I want to write a GUI/Terminal based application where I would need to clear the terminal and then write out the gui.

But how do I reset the terminal back to normal once the application is finished?


回答1:


Terminals (such as xterm and "any" which emulate it) support a feature called the alternate screen. Often, terminal descriptions include switching to/from the alternate screen in the smcup and rmcup capabilities, and it is used by ncurses applications. (The feature is not always used, because some users do not like the feature). Even if it is not part of the terminal description (seen with tgetstr("ti") or tigetstr("smcup")) your application could write the literal escape sequence.

On switching to the alternate screen, the convention (used in the terminal escape sequences) is to clear the alternate screen, putting the cursor at the upper left corner. Switching back restores the original (normal) screen and cursor location.

There is some discussion of alternate screen in the xterm FAQ Why doesn't the screen clear when running vi?.



来源:https://stackoverflow.com/questions/33205630/temporarily-clear-the-terminal-in-linux

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