暂时清除 Linux 中的终端

Temporarily clear the terminal in Linux

我想编写一个基于 GUI/Terminal 的应用程序,我需要清除终端然后写出 gui。

但是应用程序完成后如何将终端恢复正常?

终端(例如 xterm 和模拟它的 "any")支持称为备用屏幕的功能。通常,终端描述包括在 smcuprmcup 功能中切换 to/from 备用屏幕,它被 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") 使用)您的应用程序可以编写文字转义序列。

切换备用屏幕时,约定(用于终端转义序列)是清除备用屏幕,将光标放在左上角。切换回来恢复原始(正常)屏幕和光标位置。

xterm 常见问题解答中有一些关于备用屏幕的讨论 Why doesn't the screen clear when running vi?