ncurses 的奇怪行为取决于 TERM 值

ncurses 的奇怪行为取决于 TERM 值

我试图理解以下问题。考虑以下 ncurses 程序:

#include <curses.h>
int main() {
  initscr(); noecho(); printw("0000000"); getch();
}

编译为:

$ gcc -o t t.c -lncurses

这是我使用默认设置看到的内容(exec 行很简单$ ./t):

0

这看起来很奇怪。我可以使用 来验证这一点script。这是我得到的:

$ teseq typescript
|Script started on 2020-04-02 08:52:58+02:00 [TERM="xterm-256color" TTY="/de|-
-|v/pts/0" COLUMNS="211" LINES="46"]|.
: Esc ]
& OSC: OPERATING SYSTEM COMMAND
|0;malat@remote: /tmp|
. BEL/^G
: Esc [ 1 ; 32 m
& SGR: SELECT GRAPHIC RENDITION
" Set bold text.
" Set foreground color green.
|malat@remote|
: Esc [ 0 m
& SGR: SELECT GRAPHIC RENDITION
" Clear graphic rendition to defaults.
|:|
: Esc [ 1 ; 34 m
& SGR: SELECT GRAPHIC RENDITION
" Set bold text.
" Set foreground color blue.
|/tmp|
: Esc [ 0 m
& SGR: SELECT GRAPHIC RENDITION
" Clear graphic rendition to defaults.
|$ ./t|
. CR/^M LF/^J
: Esc [ ? 1049 h
& SM: SET MODE (private params)
" (Xterm) Save the cursor position and use the alternate screen buffer,
"  clearing it first.
: Esc [ 22 ; 0 ; 0 t
: Esc [ 1 ; 46 r
" (DEC) Set the scrolling region to from line 1 to line 46.
: Esc ( B
& GZD4: G0-DESIGNATE 94-SET
" Designate 94-character set B (US-ASCII) to G0.
: Esc [ m
& SGR: SELECT GRAPHIC RENDITION
" Clear graphic rendition to defaults.
: Esc [ 4 l
& RM: RESET MODE
" INSERTION REPLACEMENT MODE (IRM) -> REPLACE
: Esc [ ? 7 h
& SM: SET MODE (private params)
" (DEC) Text auto-wrap mode.
: Esc [ H
& CUP: CURSOR POSITION
" Move the cursor to line 1, column 1.
: Esc [ 2 J
& ED: ERASE IN PAGE
" Clear the screen.
|0|
: Esc [ 6 b
& REP: REPEAT
: Esc [ 46 ; 1 H
& CUP: CURSOR POSITION
" Move the cursor to line 46, column 1.
: Esc [ ? 1049 l
& RM: RESET MODE (private params)
" (Xterm) Leave the alternate screen buffer and restore the cursor.
: Esc [ 23 ; 0 ; 0 t
. CR/^M
: Esc [ ? 1 l
& RM: RESET MODE (private params)
" (DEC) Cursor key mode off.
: Esc >
& DECKPNM: KEYPAD NORMAL MODE
: Esc ]
& OSC: OPERATING SYSTEM COMMAND
|0;malat@remote: /tmp|
. BEL/^G
: Esc [ 1 ; 32 m
& SGR: SELECT GRAPHIC RENDITION
" Set bold text.
" Set foreground color green.
|malat@remote|
: Esc [ 0 m
& SGR: SELECT GRAPHIC RENDITION
" Clear graphic rendition to defaults.
|:|
: Esc [ 1 ; 34 m
& SGR: SELECT GRAPHIC RENDITION
" Set bold text.
" Set foreground color blue.
|/tmp|
: Esc [ 0 m
& SGR: SELECT GRAPHIC RENDITION
" Clear graphic rendition to defaults.
|$ exit|
. CR/^M LF/^J LF/^J
|Script done on 2020-04-02 08:53:04+02:00 [COMMAND_EXIT_CODE="1"]|.

然而,当我现在这样做时:

$ TERM=xterm-color ./t

我可以看到预期的输出:

0000000

我在这里缺少什么?

答案1

事实证明,这是 REP(重复前一个字符)转义序列的一个已知问题。也可以看看:

这个问题在 Debian 中已经得到了修复:

相关内容