Reputation: 1248
I'm writing an ncurses application, and there's a strange issue with how special characters are printed to the screen. Here's an example:
#include <ncurses.h>
int main(int argc, char *argv[])
{
initscr();
noecho();
keypad(stdscr, TRUE);
cbreak();
curs_set(0);
addch(ACS_LARROW);
addch(' ');
addch(ACS_UARROW);
addch(' ');
addch(ACS_DARROW);
addch(' ');
addch(ACS_RARROW);
addch(' ');
refresh();
getch();
endwin();
return 0;
}
So, when I run this on a tty, the characters are correctly printed as arrows (←, ↑, ↓, →), but when I try and run this on a terminal (I've tried on gnome-terminal and LXTerminal) this is the output:
< ^ v >
Is there any reason for this difference? I thought it might be font related, but I'm really out of my territory here, and my googling didn't help.
Any suggestion on how to force lxterminal (or any other terminal) to output the same characters of the tty?
Upvotes: 2
Views: 3926
Reputation: 54465
The setting of TERM
is largely irrelevant. What matters is
The usual reason for this is that the program is built-with and linked-to the ncurses library rather than ncursesw:
screen
are known special cases where the terminfo cannot describe the behavior of the terminal. For others (terminals which do not support VT100 line-drawing in UTF-8 mode), you would set NCURSES_NO_UTF8_ACS
.U8
note in the terminal database). However, most people set TERM to xterm
or linux
and often equate those (see note in xterm FAQ).Upvotes: 1
Reputation: 16855
ncurses decides which character to output for ACS_LARROW and friends based on your termtype. It's likely that in a tty your termtype is set to 'linux', whereas in gnome-terminal, etc it'll most likely be set to 'xterm'. Although I'm not certain, it's quite possible that the xterm termtype doesn't support these characters.
You could try running you application as so:
env TERM=linux ./a.out
Other termtypes to try are gnome, rxvt and vt102. These will output extended ASCII characters and your terminal emulator should support them. You could also try rxvt-unicode if you have it installed, that should output the correct unicode codepoints for these special symbols.
Upvotes: 4
Reputation: 6070
terminal emulations are sometimes coded in 7bit ASCII, and there is no corresponding Value for the arrows (with line and wedge) in this code page, so the terminal displays what comes near (that is: only the wedge). on tty you have all the capacities of you computer (UTF-8, color encoding, ...), so the terminal can draw the arrow.
Upvotes: 1