诅咒如何保留屏幕内容? [英] How curses preserves screen contents?

查看:28
本文介绍了诅咒如何保留屏幕内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您启动 (n)curses 程序时,它会从您的终端模拟器中移除滚动条,清除屏幕,滚动日志(历史记录)也会消失.退出程序时,屏幕内容重新出现,滚动条返回,滚动缓冲区返回.

When you start the (n)curses program, it will remove the scroll bar from your terminal emulator, clear the screen, the scroll log (history) will also disappear. When you exit the program, the screen contents reappears, the scroll bar returns, and the scroll buffer returns.

ncurses 是如何做到的?我已经研究了所有的 ANSI 转义码,我看不到任何可以做这样的事情的东西.这背后的技术是什么?

How ncurses does it? I have studied all ANSI escape codes, I cannot see anything that can do such things. What is the technology behind this?

推荐答案

该技术名为 备用屏幕缓冲区.终端仿真器提供两种模式:主模式和备用模式.备用屏幕缓冲区没有回滚,当您在这些缓冲区之间切换时,它们中的内容会被保留.要在它们之间切换,请使用 smcuprmcup ANSI 转义序列.以二进制形式,它们是:

The technology is called The Alternate Screen Buffer. Terminal emulator provides two modes: primary and alternate. Alternate screen buffer has no scroll back, when you switch between these buffers the contents in them is preserved. To switch between them use smcup and rmcup ANSI Escape Sequences. In binary form they are:

$ tput smcup|hexdump -C 
00000000  1b 5b 3f 31 30 34 39 68                           |.[?1049h|

$ tput rmcup|hexdump -C 
00000000  1b 5b 3f 31 30 34 39 6c                           |.[?1049l|

这篇关于诅咒如何保留屏幕内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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