vi退出终端后如何恢复终端内容? [英] How does vi restore terminal content after quitting it?

查看:147
本文介绍了vi退出终端后如何恢复终端内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

vi或man之类的程序或任何其他程序如何用该程序自己的内容替换终端内容,然后在退出这些程序后将其带回旧的终端内容?

解决方案

Vi切换到终端支持的备用屏幕缓冲区.这是通过使用转义序列来实现的.有关完整的详细信息,请参见此链接. >

这些的termcap条目为"ti"输入,而为"te"退出全屏模式.

正如@Celada在下面指出的那样,对xterm转义序列进行硬编码不是一个好主意;因为这些序列根据$ TERM的不同而有所不同,例如:

xterm-color
  ti: <Esc> 7 <Esc> [ ? 47 h
  te: <Esc> [ 2 J <Esc> [ ? 4 7 l <Esc> 8

xterm-256color
  ti: <Esc> [ ? 1 0 4 9 h
  te: <Esc> [ ? 1 0 4 9 l

另一方面,如今,xterm支持在非xterm终端中非常广泛.仅支持xterm不太可能引起问题,除非用户使用$ TERM设置异常或过时.资料来源:我支持执行此操作的产品.

How does a program like vi or man or any other program replace the terminal content with the program's own contents then after quitting those programs they bring back the old terminal content?

解决方案

Vi flips to the alternate screen buffer, supported by terminals. This is achieved using escape sequences. See this link for full details.

The termcap entry for these are 'ti' to enter, and 'te' to exit full-screen mode.

As @Celada points out below, hardcoding xterm escape sequences is not a Good Idea™, because the sequences vary according to $TERM, for example:

xterm-color
  ti: <Esc> 7 <Esc> [ ? 47 h
  te: <Esc> [ 2 J <Esc> [ ? 4 7 l <Esc> 8

xterm-256color
  ti: <Esc> [ ? 1 0 4 9 h
  te: <Esc> [ ? 1 0 4 9 l

On the other hand, xterm support is very broad these days among non-xterm terminals. Supporting only xterm is unlikely to cause problems, except for users with exotic or obsolete $TERM settings. Source: I support products that do this.

这篇关于vi退出终端后如何恢复终端内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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