nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.66k stars 372 forks source link

Weird characters with ncurses 6.1 #185

Closed agostonbarna closed 6 years ago

agostonbarna commented 6 years ago

After upgrading ncurses to v6.1 weird characters appear on the screen when I try to use peco.

$ cat test.txt       
line 1
line 2
line 3
$ cat test.txt | peco
 �����������������������[%i%p1%dG                            [3 (1/1)]
line 1
line�2�������������������������������
����������������������������������  
line�3��[%i%p1%dG
Waiting for input...
�����������������������������  

Thanks to @mattn I learned that peco uses termbox-go under the hood and that the issue might happen because terminfo was also modified with the latest ncurses upgrade.

infocmp diff:

45c45
<   pairs= 32767.
---
>   pairs= 65536.
173c173
<   kmous= '\E[M'.
---
>   kmous= '\E[<'.
190c190
<   rmcup= '\E[?1049l'.
---
>   rmcup= '\E[?1049l\E[23;0;0t'.
206c206
<   smcup= '\E[?1049h'.
---
>   smcup= '\E[?1049h\E[22;0;0t'.

ncurses version: 6.1.20180127 TERM: xterm-256color OS: Arch Linux Linux kernel: 4.14.20-1-lts, x86_64

peco/peco#446

syui commented 6 years ago

Are you using tmux ?

agostonbarna commented 6 years ago

Normally yes, but I did the test without tmux.

cfstras commented 6 years ago

Tested with Hyper, gnome-terminal, even with disabling all .profile&zshrc. (all broken) xterm and bare linux console work...

Did a diff of "set" between gnome-terminal and xterm, found a workaround:

TERM=xterm #works!!!

Seems like the bug only gets triggered with TERM=xterm-256color

cfstras commented 6 years ago

Downgrading to ncurses-6.0-20180121 did NOT work. Downgrading to ncurses-6.0 (found on https://ftp.gnu.org/pub/gnu/ncurses/ ) WORKS.

For anyone on Arch Linux, I've created a PKGBUILD file that gets you going quickly: https://gist.github.com/cfstras/f8634870126cb5b84c76a30200c2b603

k2nr commented 6 years ago

Same here with peco & opensuse tumbleweed. TERM=xterm worked for me

kevinschoon commented 6 years ago

Confirmed I am seeing this bug as well with ncurses 6.1 on Arch. It will effect anything using this lib including the many popular tools built on termui. TERM=xterm ./my-program will fix the issue. It's not immediately clear to me what the long term fix for this is but I imagine the maintainer will have an idea..

4.15.5-1-ARCH
glibc 2.26-11
ncurses 6.1-3
nsf commented 6 years ago

I'll have a look at it this weekend. Hopefully won't forget about it.

nsf commented 6 years ago

Should work now. Ncurses 6.1 slightly altered the terminfo file format. Quoting man page:

       On occasion, 16-bit signed integers are not large enough.  With ncurses
       6.1,  a  new format is introduced by making a few changes to the legacy
       format:

       ·   a different magic number (0542)

       ·   changing the type for the number array from signed 16-bit  integers
           to signed 32-bit integers.

Although doc implies octal number (and original magic number is also specified in octal). What I see in terminfo files is just a little endian 16-bit number 542. Whatever...