使用"备用屏幕"在bash脚本 [英] Using the "alternate screen" in a bash script

查看:215
本文介绍了使用"备用屏幕"在bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

备用屏幕的是使用像vim,HTOP,屏幕,alsamixer中,许多用户交互终端应用较少,......它就像一个不同的缓冲区终端的内容,这当应用程序退出,所以整个终端得到恢复,它看起来像应用程序没有输出任何东西消失了。

The alternate screen is used by many "user-interactive" terminal applications like vim, htop, screen, alsamixer, less, ... It is like a different buffer of the terminal content, which disappears when the application exits, so the whole terminal gets restored and it looks like the application hasn't output anything.

我想实现我自己的shell(bash)的剧本完全一样的东西,但它并不一定是便携。我会坚持只和基于xterm的终端仿真器到Linux;但解决的办法应该使用类似 tput的如果可能的话。不过,我不希望使用一些外部脚本语言(甚至像C)。

I'd like to achieve exactly the same thing in my own shell (bash) script, except that it doesn't have to be that portable. I'd stick to linux only and xterm-based terminal emulators; but the solution should use something like tput if it's possible. However, I don't want to use some external scripting language (or even something like C).

虽然我并不想用C(因为它应该是一个bash脚本用尽可能少的依赖越好),我进去一看少源$ C ​​$ C。这似乎是用terminfo的数据库,并查找其初始化了钛终端能力。在拆卸线,它不使用备用sceen,所以我认为我找到了负责code线。

Although I don't want to use C (as it should be a bash-script with as few dependencies as possible), I had a look into the source code of less. It seems to use terminfo as the database and looks up the "ti" terminal capability in its initialisation. When removing the line, it doesn't use the alternate sceen, so I assumed that I found the responsible code line.

不过,我无法找到男人的terminfo 这样的能力。但也许我错了路找到了一个解决方案上。可能的terminfo / tput的是不是我的朋友。

However, I can't find such a capability in man terminfo. But maybe I'm on the wrong path finding a solution for this. Maybe terminfo / tput isn't my friend.

那么(怎样),我可以使用备用屏幕在bash脚本?是否有人知道一个简单的应用程序中,源$ C ​​$ C我可能会发现一个暗示? (C应用程序或bash脚本或任何...)

So (how) can I use the alternate screen in a bash script? Does somebody know a simple application in which source code I may find a hint? (C application or bash script or whatever...)

推荐答案

您可以使用此命令切换到备用屏幕:

You can switch to the alternate screen using this command:

$ tput smcup

和回来了:

$ tput rmcup

这些命令只是输出终端的相应转义序列。如果它是一个XTERM他们将等同于(多个已知但小于优雅或便携式):

These commands just output the appropriate escape sequences for your terminal. If it is an XTERM they will be equivalent to the (more known but less elegant or portable):

$ echo -e "\e[?1049h"

$ echo -e "\e[?1049l"

有关更多的终端控制命令看到 5人terminfo的

For more terminal control commands see man 5 terminfo.

这篇关于使用"备用屏幕"在bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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