cterminalutf-8ncursesterminfo

strange extended characters in ncurses


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?


Solution

  • 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.