Terminal
解析 terminfo u6 字元串
查看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
給出(注意參數的反轉)
^[[51;41R
如果表達式被給出為
u6=\E[%i%p2%d;%p1%dR
它會產生相同的結果。
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).
檢查最後一條評論,進行練習,
u8
但u9
對 and 沒有任何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.
雖然它包含在幾個條目中以保持完整性(不多:在 18,699 行中出現了 16 次
terminfo.src
),但該功能沒有知名使用者。事實上,在 ncurses 中有一個地方可以編寫它來使用它(tty_update.c
文件中的一些 ifdef 調試程式碼),但它使用硬編碼的轉義序列(標記為“ANSI 兼容”)。沒有使用者的原因是:
- 反轉任意 terminfo 表達式比看起來更難
- xterm 和類似的終端解釋這些轉義序列
在ECMA-48中,這些是 (u7) DSR(設備狀態報告)和 (u6) CPR(活動位置報告)。