暂时清除Linux中的终端 [英] Temporarily clear the terminal in Linux

查看:83
本文介绍了暂时清除Linux中的终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

终端(例如xterm和模拟它的"any")支持称为备用屏幕的功能.通常,终端说明包括在smcuprmcup功能中切换到备用屏幕或从备用屏幕切换到其他屏幕,并且 ncurses 应用程序. (由于某些用户不喜欢该功能,因此并不总是使用该功能).即使它不是终端描述的一部分(与 tgetstr("ti") tigetstr("smcup") ),您的应用程序可以编写文字转义序列.

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.

xterm常见问题解答中有一些关于备用屏幕的讨论 为什么不运行vi时屏幕不清晰吗? .

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

这篇关于暂时清除Linux中的终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆