简体   繁体   English

ANSI转义码序列“ ESC [> c”是什么?

[英]What is the ANSI escape code sequence “ESC[>c”?

After typing "vi [FILENAME]" in the bash I get the following result: 在bash中输入“ vi [FILENAME]”后,得到以下结果:

.... \\r\\"gu1.txt\\" 16L, 87C ESC[>cESC[1;1H 111\\r\\n1112 ..... .... \\r\\"gu1.txt\\" 16L, 87C ESC[>cESC[1;1H 111\\r\\n1112 .....

The first text marked in the this row is the file name following the number of lines and columns of the vi result. 该行中标记的第一个文本是文件名称,紧随vi结果的行数和列数。

The second text includes two escape sequences which I don't understand their meaning : ESC[>c and ESC[1;1H . 第二个文本包含两个我不理解它们含义的转义序列: ESC[>cESC[1;1H

The last text includes the text shown as a result of the vi, ie the content of the file. 最后的文本包括作为vi结果显示的文本,即文件的内容。

Can you please explain what is the ANSI escape code sequence ESC[>c and how it is related to the escape code sequence which comes right after it ESC[1;1H ? 您能否解释一下ANSI转义码序列ESC[>c以及它与ESC[1;1H之后的转义码序列之间的关系?

Thanks in advance 提前致谢

It is "Send Device Attributes (Secondary DA)" , according to XTerm Control Sequences : 根据XTerm控制序列 ,它是“发送设备属性(辅助DA)”

CSI > Ps c CSI> Ps c

Send Device Attributes (Secondary DA). 发送设备属性(辅助DA)。 Ps = 0 or omitted -> request the terminal's identification code. Ps = 0或省略->请求终端的识别码。 The response depends on the decTerminalID resource setting. 响应取决于decTerminalID资源设置。 It should apply only to VT220 and up, but xterm extends this to VT100. 它应仅适用于VT220及更高版本,但xterm会将其扩展到VT100。

The control (applied to VT220, etc.) is documented in DEC manuals on vt100.net 该控件(应用于VT220等)已记录在vt100.net上的 DEC手册中

The point of Send Device Attributes is that a program is asking the terminal something. 发送 设备属性的要点是程序正在终端询问一些内容。 The terminal sends back information, the response . 终端回信息,即响应 This happens to be a string that looks something like the request (which is helpful if the terminal is not really connected to a host). 这恰好是一个看起来像请求的字符串(如果终端未真正连接到主机,则很有用)。 The program which sent the request has to read the response, otherwise you will see odd characters printed on the terminal—the unread parts of the response. 发送请求的程序必须读取响应,否则您将看到终端上印有奇数字符,即响应的未读部分。

In the context of your question about vi , vim uses this to determine the version of xterm which it may be using. 在有关vi的问题中,vim使用它来确定它可能使用的xterm版本。 The answer is provided in the response from the terminal: 终端的响应中提供了答案:

and Pv is the firmware version (for xterm , this was originally the XFree86 patch number, starting with 95). Pv是固件版本(对于xterm ,它最初是XFree86补丁程序的编号,从95开始)。 In a DEC terminal, Pc indicates the ROM cartridge registration number and is always zero. 在DEC端子中, Pc表示ROM盒注册号,并且始终为零。

The particular feature in vim which is using this is called " termresponse ". vim中正在使用的特定功能称为“ termresponse ”。 If you use it on a terminal which pretends to be xterm, but is not really, then you will see stray characters on your terminal, as described in an answer for Why is vim starting in delete mode? 如果在伪装为xterm但不是真的xterm的终端上使用它,则您将在终端上看到流浪字符,如有关“ 为什么vim以删除模式启动?”的回答中所述 . Any terminal emulator which is "VT100 compatible" must handle this, however. 但是,任何与“ VT100兼容”的终端仿真器都必须处理此问题。

The following ESC[1;1H is not related to the Secondary DA , but rather is standard (ISO-6429 / ECMA-48 ) cursor-positioning done for initialization (and you would see something like this in any text editor running in a terminal). 以下ESC[1;1H辅助DA无关,而是完成了用于初始化的标准(ISO-6429 / ECMA-48 )光标定位(您会在终端中运行的任何文本编辑器中看到类似的内容)。 Usually it is sent in a shorter form, ESC[H , since the numbers default to 1 . 通常,它以较短的形式ESC[H ,因为数字默认为1

The ESC[>c is a private mode sequence, as indicated by the > character. ESC[>c私有模式序列,如>字符所示。 That (and many other details) are described in ECMA-48. ECMA-48中对此进行了描述(以及许多其他细节)。 DEC's terminals followed the standard, along with extensions. DEC的终端及其扩展符合标准。 The "ANSI" standard for terminal controls was long ago subsumed into the ISO standard, and (still) long ago the corresponding ANSI standard was withdrawn. 终端控制的“ ANSI”标准很早以前已包含在ISO标准中,并且很久以前(仍然)撤消了相应的ANSI标准。

You would be unlikely to encounter this sequence used in communicating with a hardware terminal, since it was (before xterm began using it in the 1990s) predominantly used by DEC's (Open)VMS systems to determine what types of terminals were connected to it. 您不太可能会遇到用于与硬件终端进行通信的顺序,因为该顺序(在xterm在1990年代开始使用它之前)是DEC(Open)VMS系统主要用来确定与其连接的终端类型。

I believe the ANSI standard isn't available publicly, but a quick Google turned up a third-party summary based on the DEC PDP-10 docs . 我认为ANSI标准不是公开可用的,但是Google很快就根据DEC PDP-10文档提出了第三方摘要

For the first one: The 'c' command means "DA" for "Device Attributes". 对于第一个: 'c'命令的意思是“设备属性”的“ DA”。 You send a CSI 'c' with no arguments to the terminal, and it sends back a CSI 'c' with private mode characters that mean something terminal-specific. 您发送CSI 'c'不带参数的终端,并将其发送回CSI 'c'与意味着什么终端特定的私模人物。 Private mode characters must start with one of "<=>?" 专用模式字符必须以"<=>?"之一开头 , and run up to a digit, trailing character, or letter. ,并以数字,结尾字符或字母开头。 So, ESC[>c is a minimal response that somehow encodes 2 bits of terminal-specific information (by choosing > over one of the other 3 choices). 因此, ESC[>c是一个最小响应,它以某种方式对2位终端特定信息进行编码(通过在其他3个选择之一中选择> )。 Note that ESC[>c is equivalent to ESC[>0c , which is how DEC VT240 terminals distinguished themselves from VT220, so this may mean that your text file was captured from output intended for a VT240 emulator. 请注意, ESC[>c等效于ESC[>0c ,这是DEC VT240终端与VT220区别的方式,因此这可能意味着您的文本文件是从用于VT240仿真器的输出中捕获的。 But it could mean all kinds of other things. 但这可能意味着其他各种事情。 At any rate, sending that back to the terminal should have no effect. 无论如何,将其发送回终端都将无效。

The second one is a lot easier. 第二个要容易得多。 The 'H' command means "CUP", for "CUrsor Position": given arguments n and m , it moves the cursor to 1-based row n and column m from the top left. 'H'命令的意思是“ CUP”,对于“光标位置”:给定参数nm ,它将光标从左上角移至基于1的行n和列m So, ESC[1;1H moves the cursor to the top-left corner of the screen. 因此, ESC[1;1H将光标移动到屏幕的左上角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM