我如何解码 xterm 响应?
How do I decode xterm responses?
我正在构建一个应用程序,它使用 pty.js 在我的计算机上打开一个伪终端。我收到的回复如下所示:
]0;ec2-user@ip-172-31-62-237:~[?1034h[ec2-user@ip-172-31-62-237 ~]$ ls
]0;ec2-user@ip-172-31-62-237:~[ec2-user@ip-172-31-62-237 ~]$ pwd
/home/ec2-user
我假设 pty.js 正在发回特定的编码,但我不确定编码是什么以及如何对其进行解码。如有任何帮助,我们将不胜感激。
那些不是响应(终端会响应),而是应用程序(不是终端)发送的控制序列。我看到一些实例(如果转义字符显示为 ^[
,OSC 可能打印为 ^[]
,而 CSI 可能打印为 ^[[
):
]0;ec2-user@ip-172-31-62-237:~
看起来像设置 window 标题的控件(来自 xterm,尽管有几个程序支持它),
OSC Ps ; Pt BEL
OSC Ps ; Pt ST
...
Ps = 0 -> Change Icon Name and Window Title to Pt.
和
[?1034h
看起来像 xterm 的曲目中的另一个序列(其他程序通常不支持):
CSI ? Pm h
DEC Private Mode Set (DECSET).
...
Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
(enables the eightBitInput resource).
对于给定的示例,编码 不是一个因素。
为了捕获应用程序的输出,script
program is useful. I use a small utility (unmap) 将生成的 typescript
文件转换为可读形式,但 cat -v
通常足以满足此目的。
进一步阅读:XTerm Control Sequences
我正在构建一个应用程序,它使用 pty.js 在我的计算机上打开一个伪终端。我收到的回复如下所示:
]0;ec2-user@ip-172-31-62-237:~[?1034h[ec2-user@ip-172-31-62-237 ~]$ ls
]0;ec2-user@ip-172-31-62-237:~[ec2-user@ip-172-31-62-237 ~]$ pwd
/home/ec2-user
我假设 pty.js 正在发回特定的编码,但我不确定编码是什么以及如何对其进行解码。如有任何帮助,我们将不胜感激。
那些不是响应(终端会响应),而是应用程序(不是终端)发送的控制序列。我看到一些实例(如果转义字符显示为 ^[
,OSC 可能打印为 ^[]
,而 CSI 可能打印为 ^[[
):
]0;ec2-user@ip-172-31-62-237:~
看起来像设置 window 标题的控件(来自 xterm,尽管有几个程序支持它),
OSC Ps ; Pt BEL
OSC Ps ; Pt ST
...
Ps = 0 -> Change Icon Name and Window Title to Pt.
和
[?1034h
看起来像 xterm 的曲目中的另一个序列(其他程序通常不支持):
CSI ? Pm h
DEC Private Mode Set (DECSET).
...
Ps = 1 0 3 4 -> Interpret "meta" key, sets eighth bit.
(enables the eightBitInput resource).
对于给定的示例,编码 不是一个因素。
为了捕获应用程序的输出,script
program is useful. I use a small utility (unmap) 将生成的 typescript
文件转换为可读形式,但 cat -v
通常足以满足此目的。
进一步阅读:XTerm Control Sequences