Reputation: 373
I am developing an ncurses application myself in C. The problem is that putty displays alternative character set characters like ACS_VLINE as letters. My locale is
LANG=en_US.UTF-8
and I have set
export NCURSES_NO_UTF8_ACS=1
I have also set putty to UTF-8 and tried different fonts. The characters display fine on the tty on the actual machine so I think the issue is with putty. I have also tried linking ncursesw instead of ncurses.
Upvotes: 7
Views: 5185
Reputation: 2883
I want to make some additions. I faced same issue: many ncurses-based tools like dialog
, menuconfig
and nconfig
from Linux kenrel sources, even mc
is broken when built with ncurses (although mc
is built using Slang on many OSes and not affected).
Here is what happened
ncurses uses smacs
record from terminfo to switch to "alternative charset" and then it uses acsc
to draw boxes. It sends a
which is box-drawing character in alternative charset (ACS).
This is VT100 graphics.
Some terminal emulators nowadays do not support ACS when in UTF-8 because apps have ability to send real box-drawing codepoints.
There is unofficial capability U8
(capital U!) in terminfo
that tells ncurses: "Instead of ACS use real box-drawing codepoints."
I have this capability infocmp -x xterm-utf
and for putty aswell, but not for xterm
.
As you can read in ncurses(3)
(https://invisible-island.net/ncurses/man/ncurses.3x.html), ncurses
is aware of Linux console and GNU screen (and tmux, which also uses screen
as TERM
) and always behave like if U8
were set.
For other terminals that do not support ACS when in UTF, you can set NCURSES_NO_UTF8_ACS
.
Unfortunatelly, ncurses is not aware of putty.
There is also luit
that may convert ACS to Unicode points.
So, here is what we can do to run ncurses + putty in UTF-8:
Use terminal with U8#1
capability. This one is set for putty (btw, I suggest to use putty-256color
instead). You can create your own entry with U8#1
and colors#256
and compile it with tic -x
. Be carefull that mouse may not work on terminals that do not start with xterm
(see mouseinterval(3)
, BUGS section). This is why I do not use putty
terminal. I suggest to copy xterm-utf8
, add colors#256
, compile and stay with it: it works perfectly with putty, mouse and utf8.
You can set NCURSES_NO_UTF8_ACS
in your profile.
You can run screen
or tmux
: it will set TERM
to screen
and fix ncurses
You can run luit
: it will do all convertions for you.
Since putty 0.71 you can ask putty to support ACS drawings even in UTF-8
Upvotes: 7
Reputation: 54563
It is a combination of things. The recommended TERM
for PuTTY is "putty", but due to inertia, most people use "xterm". The line-drawing support in the xterm terminal description is different from PuTTY's assumptions because xterm supports luit, which has some limitations with the way the alternate character set is managed (see Debian Bug report #254316:
ncurses-base: workaround for screen's handling of register sgr0 isn't quite right).
If you use infocmp
to compare, you may see these lines which deal with the alternate character set:
acsc: '``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~', '``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~'.
enacs: NULL, '\E(B\E)0'.
rmacs: '\E(B', '^O'.
smacs: '\E(0', '^N'.
VT100s can have two character sets "designated", referred to as G0 and G1:
Although both are VT100-compatible, the xterm scheme does not work with PuTTY. Because of the tie-in with luit
, the normal terminal description for xterm
will not change (unless it proves possible to modify luit
to solve the problem for its users), so a workaround is needed for users of PuTTY:
use a different terminal description as recommended, e.g., TERM=putty
. PuTTY's settings dialog lets you set environment variables to pass to the remote machine.
This has the drawback that some systems do not have the full ncurses terminal database installed, due to "size" (it is 6.8Mb on my local machine). Also, TERM
may not be on the list of allowed ssh environment variables.
you can compile your own terminfo entry with ncurses' tic, e.g.,
cat >foo <<"EOF"
xterm|my terminfo entry,
enacs=\E(B\E)0,
rmacs=^O,
smacs=^N,
use=xterm-new,
EOF
tic foo
use GNU screen. It does its own fixes, and happens to compensate for PuTTY's problems.
Further reading
Upvotes: 7