在 Linux 中临时清除终端 [英] Temporarily clear the terminal in Linux

查看:24
本文介绍了在 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天全站免登陆