
Estou tentando entender o seguinte problema. Considere o seguinte programa ncurses:
#include <curses.h>
int main() {
initscr(); noecho(); printw("0000000"); getch();
}
Compilação é:
$ gcc -o t t.c -lncurses
Aqui está o que vejo usando a configuração padrão (a linha exec é simplesmente $ ./t
):
0
O que parece estranho. Posso verificar isso usando script
. Aqui está o que eu recebo:
$ 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"]|.
No entanto, quando eu faço agora:
$ TERM=xterm-color ./t
Posso ver o resultado esperado:
0000000
O que estou perdendo aqui ?
Responder1
Acontece que este é um problema conhecido com a sequência de escape REP (repetir caractere anterior). Veja também:
Isso foi corrigido da maneira mais difícil no Debian: