> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man4/screen.4.md).

# screen.4

`screen` — PC 显示接口

## 名称

`screen`

## 描述

通过设备文件 **`/dev/ttyv0`** 到 **`/dev/ttyvb`** 访问 *虚拟控制台*。每个文件对应一个独立的虚拟控制台。所有虚拟控制台设备可以同时打开，但同一时间只有一个处于活动状态。活动的虚拟控制台“拥有”键盘和显示屏。

输出到当前未显示在屏幕上的虚拟控制台的内容保存在一个可容纳“一屏”（通常为 25 行）的缓冲区中。写入 **`/dev/console`**（原始控制台设备）的任何输出都会回显到 **`/dev/ttyv0`**。

要在虚拟控制台之间切换，使用组合键 *ALT+Fn*，即按住 ALT 并按下一个功能键。具有与功能键相同编号的虚拟控制台随即被选为当前虚拟控制台，并独占使用键盘和显示屏。此切换序列可通过键盘映射 ioctl 调用更改（参见 [keyboard(4)](/man/man4/keyboard.4.md)）。

控制台允许通过特殊按键序列输入键盘上物理不存在的值。要使用此功能，按住 ALT，然后通过数字小键盘输入 0-255 的十进制数，然后释放 ALT。输入的值即用作一个字符的 ASCII 值。这样就可以输入任何 ASCII 值。控制台驱动程序还包括历史功能。通过按下 scroll-lock 键激活。这会保持显示，并启用光标箭头键在最近滚出的行中上下滚动。

控制台理解 ANSI x3.64 字符序列的子集。为与旧的 pccons 兼容，还支持 PC3 字符序列。

```sh
ANSI	Seq	功能					Termcap 条目
======= ======= =====================================   ==============
--	E7	保存光标位置				sc
--	E8	恢复已保存的光标位置			rc
--	Ec	重置					rs
--	EM	光标上移 1 行，			--
		如在顶部则滚动
CUU     E[nA    光标上移 n 行                           up/UP (ku)
CUD     E[nB    光标下移 n 行                           do/DO (kd)
CUF     E[nC    光标右移 n 字符                         nd/RI (kr)
CUB     E[nD    光标左移 n 字符                         --/LE (kl)
HPA     E[n`    光标移至字符位置 n                      ch
HPR	E[na	光标右移 n 字符 			--
VPA     E[nd    光标移至行 n                            cv
VPR	E[ne	光标下移 n 行				--
CPL     E[nF    光标移至行首，                          -- (@7)
		上移 n 行
CNL     E[nE    光标移至行首，                          nw
		下移 n 行
CUP	E[y;xH	光标移至 x, y				cm
HVP	E[y;xf	光标移至 x, y				--
CBT     E[nZ    光标后退 n 个制表位                     bt (kB)
IL      E[nL    插入 n 个空行                           al/AL
ICH     E[n@    插入 n 个空字符                         ic/IC
DL      E[nM    删除 n 行                               dl/DL
DCH     E[nP    删除 n 个字符                           dc/DC
ED	E[nJ	擦除显示部分或全部：			cd
		n=0 从光标到显示末尾，
		n=1 从显示开头到光标，
		n=2 整个显示。
EL	E[nK	擦除行部分或全部：			ce
		n=0 从光标到行末，
		n=1 从行首到光标，
		n=2 整行。
ECH     E[nX    擦除 n 个字符                           ec
SU      E[nS    显示向上滚动 n 行（正向）                sf/SF
SD      E[nT    显示向下滚动 n 行（反向）                sr/SR
SGR	E[nm	设置字符属性：				--
		n= 0  正常属性（全部关闭）
		n= 1  粗体（高亮）
		n= 4  下划线（如硬件支持）
		n= 5  闪烁（如硬件支持）
		n= 7  反转
		n= 22 取消粗体
		n= 24 取消下划线
		n= 25 取消闪烁
		n= 27 取消反转
		n= 3X 设置 ANSI 前景色
		      （见表）
		n= 4X 设置 ANSI 背景色
		      （见表）
		   X=0 黑色 	X=1 红色
		   X=2 绿色	X=3 棕色
		   X=4 蓝色	X=5 品红
		   X=6 青色	X=7 浅灰
		   X=9 重置为正常颜色
--	E[s	保存光标位置				sc
--	E[u	恢复已保存的光标位置			rc
--      E[x     将正常颜色和属性重置                  --
		为默认值
--	E[nz	切换到虚拟控制台 n			--
--      E[1;nx  将正常 ANSI 背景色设置                --
		为 n（见表）
--      E[2;nx  将正常 ANSI 前景色设置                --
		为 n（见表）
--      E[3;nx  直接设置正常视频属性                  --
		为 n（n 从 0 到 255）
--      E[5;nx  将正常 ANSI 反转背景色                --
		设置为 n（见表）
--      E[6;nx  将正常 ANSI 反转前景色                --
		设置为 n（见表）
		   n= 0	黑色	   n= 8	深灰
		   n= 1	红色	   n= 9	浅红
		   n= 2	绿色	   n=10	浅绿
		   n= 3	棕色	   n=11	黄色
		   n= 4	蓝色	   n=12	浅蓝
		   n= 5	品红	   n=13	浅品红
		   n= 6	青色	   n=14	浅青
		   n= 7	浅灰	   n=15	白色
--      E[7;nx  直接将正常反转视频属性                --
		设置为 n（n 从 0 到 255）
--	E[=p;dB	设置铃声音调 (p) 和持续时长 (d)，	--
			音调单位为 840 nS，
			持续时长单位为 0.1 S。
--	E[=tC	设置全局光标类型（见表）		--
		   t=0 正常不闪烁
		   t=1 正常闪烁
		   t=2 自定义不闪烁
		   t=3 自定义闪烁
		   t=4 重置光标（重置自定义
		       光标形状并将当前
		       光标类型设置为 0）
		   t=5 隐藏光标
--	E[=s;eC	设置自定义光标形状，其中		--
		s 为起始扫描行，e 为结束扫描行。
--	E[=s;e;dC					--
		同上，但 d 指定
		方向。若为 0，扫描行从
		顶部到底部计数。若为 1，从
		底部到顶部。
--	E[=tS	设置本地光标类型（见表）		--
		   t=0 正常（全局）			ve
		   t=1 不可见				vi
		   t=2 非常可见			vs
--      E[=nA   将边框颜色设置为 n                     --
		（见表）（如硬件支持）
--      E[=nF   将正常前景色设置为 n                   --
		（见表）
--      E[=nG   将正常背景色设置为 n                   --
		（见表）
--      E[=nH   将正常反转前景色                      --
		设置为 n（见表）
--      E[=nI   将正常反转背景色                      --
		设置为 n（见表）
		   n= 0	黑色	   n= 8	深灰
		   n= 1	蓝色	   n= 9	浅蓝
		   n= 2	绿色	   n=10	浅绿
		   n= 3	青色	   n=11	浅青
		   n= 4	红色	   n=12	浅红
		   n= 5	品红	   n=13	浅品红
		   n= 6	棕色	   n=14	黄色
		   n= 7	浅灰	   n=15	白色
注：序列中的第一个 E 代表 ESC（0x1b）
```

## 作者

S(/oren Schmidt <sos@FreeBSD.org>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man4/screen.4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
