ibu*_*fen 6 terminal xterm ncurses console terminfo
查看terminfo和Parameterized Strings。
一些例子来自infocmp -1 xterm
:
cud=\E[%p1%dB
,给定参数13
:
\E
=><ESC>
[
=> [
%p1
将参数 1 (13)推入堆栈%d
POP 并从堆栈打印为有符号十进制 => 13
<ESC>[13B
csr=\E[%i%p1%d;%p2%dr
,给定参数13, 16
:
\E
=><ESC>
[
=> [
%i
递增参数 1 和 2:++13、++16 给出 14、17%p1
将参数 1 (14)推入堆栈。%d
POP 并从堆栈打印为有符号十进制。=>14
;
=> ;
%p2
将参数 2 (17)推入堆栈。%d
POP 并从堆栈打印为有符号十进制。=>17
r
=> r
<ESC>14;17r
但是,……怎么读这个?
u6=\E[%i%d;%dR
处理后,\E[%i
我们<ESC>[
增加了参数 1 和 2(如果有)。但是堆栈是空的。不应该%d
从堆栈中弹出和打印两个数字吗?
没有%p
标记是 ncurses 的一个怪癖:terminfo 编译器 ( tic ) 识别 terminfo(%p1
用于标记参数)或 termcap(依赖于参数约定)。这将是一个合法的termcap表达式。由于tic知道如何处理 termcap 表达式,因此显示的字符串“足够接近”,无需进一步翻译。
你可以看到 ncurses 使用了什么tput
,例如,
tput u6 40 50
Run Code Online (Sandbox Code Playgroud)
给出(注意参数的反转)
^[[51;41R
Run Code Online (Sandbox Code Playgroud)
如果表达式被给出为
u6=\E[%i%p2%d;%p1%dR
Run Code Online (Sandbox Code Playgroud)
它会产生相同的结果。
u6-u9 功能是ncurses终端数据库中记录的早期扩展:
# INTERPRETATION OF USER CAPABILITIES
#
# The System V Release 4 and XPG4 terminfo format defines ten string
# capabilities for use by applications, <u0>...<u9>. In this file, we use
# certain of these capabilities to describe functions which are not covered
# by terminfo. The mapping is as follows:
#
# u9 terminal enquire string (equiv. to ANSI/ECMA-48 DA)
# u8 terminal answerback description
# u7 cursor position request (equiv. to VT100/ANSI/ECMA-48 DSR 6)
# u6 cursor position report (equiv. to ANSI/ECMA-48 CPR)
#
# The terminal enquire string <u9> should elicit an answerback response
# from the terminal. Common values for <u9> will be ^E (on older ASCII
# terminals) or \E[c (on newer VT100/ANSI/ECMA-48-compatible terminals).
#
# The cursor position request (<u7>) string should elicit a cursor position
# report. A typical value (for VT100 terminals) is \E[6n.
#
# The terminal answerback description (u8) must consist of an expected
# answerback string. The string may contain the following scanf(3)-like
# escapes:
#
# %c Accept any character
# %[...] Accept any number of characters in the given set
#
# The cursor position report (<u6>) string must contain two scanf(3)-style
# %d format elements. The first of these must correspond to the Y coordinate
# and the second to the %d. If the string contains the sequence %i, it is
# taken as an instruction to decrement each value after reading it (this is
# the inverse sense from the cup string). The typical CPR value is
# \E[%i%d;%dR (on VT100/ANSI/ECMA-48-compatible terminals).
#
# These capabilities are used by tack(1m), the terminfo action checker
# (distributed with ncurses 5.0).
Run Code Online (Sandbox Code Playgroud)
检查最后的评论,粘性练习u8
和u9
,但不做任何处理u6
和u7
。
扩展是在 1995 年初添加的:
# 9.3.4 (Wed Feb 22 19:27:34 EST 1995):
# * Added correct acsc/smacs/rmacs strings for vt100 and xterm.
# * Added u6/u7/u8/u9 capabilities.
# * Added PCVT entry.
Run Code Online (Sandbox Code Playgroud)
尽管出于完整性考虑,它包含在多个条目中(数量不多:在 18,699 行中出现了 16 次terminfo.src
),但没有该功能的知名用户。事实上,在 ncurses 中有一个地方可以编写它来使用它(tty_update.c
文件中的一些 ifdef 调试代码),但是使用硬编码的转义序列(标记为“ANSI 兼容”)。
没有用户的原因是:
在ECMA-48 中,它们是 (u7) DSR(设备状态报告)和 (u6) CPR(活动位置报告)。