Using curses with Linux console

consolencursestext-user-interface

I'm trying to use Curses on Fedora 12 to output status information to a VT (one of the terminals you can get to by pressing Ctrl+Alt+Fx).

When I start up my application on one of VTs ($TERM=linux) the lines for the boxes come out as the characters such as j, q, k and a few other characters. Yet when I start it within a terminal window ($TERM=xterm) everything displays as it should.

Can someone explain to me what I need to do to get the VT output to appear as the xterm? Is there a terminal setting that I can set from within my program to cause the output to be correct?

Best Answer

From the ncurses FAQ http://invisible-island.net/ncurses/ncurses.faq.html

Line-drawing characters come out as x's and q's

The x's and q's correspond to a table (from terminfo/termcap) which tells ncurses how to map the "alternate" character set to the terminal's set of graphic characters. The reference for this table comes from the vt100. If the unmapped characters appear, then the terminal emulator does not recognize the escape sequence for switching between normal and alternate fonts that is given in the terminfo description.

There are several cases of note:

  • Terminal emulators which use a different escape sequence or different range for mapping the resulting characters. For instance the so-called vt100-compatibles such as Linux console and Tera Term.
  • Terminal emulators which are locale-sensitive. Again, Linux console is a problem area when running in UTF-8 mode, since its nominal vt100-compatibility is further lessened by ignoring the escape sequences dealing with fonts. The screen utility also has the same problem; whether to make the implementation simple or to copy the Linux console, it ignores vt100-style font switching when the locale is a UTF-8 flavor.
  • If you happen to be using Solaris, it is often configured to prefer its terminal database to ncurses, even when ncurses is installed. However, its terminal description for xterm omits the enacs which is used to enable line-drawing. This does not work well with applications such as screen and luit.

For the first case, you simply have to find the correct terminfo description. Fixing the latter is harder, since the damage is done outside ncurses. (Though one can easily make things compatible enough that this particular issue would never appear, that style of solution is not deemed proper by some coders).

The normal ncurses libraries support 8-bit characters. The ncurses library can also be configured (--enable-widec) to support wide-characters (for instance Unicode and the UTF-8 encoding). The corresponding wide-character ncursesw libraries are source-compatible with the normal applications. That is, applications must be compiled and linked against the ncursesw library.

The ncurses 5.3 release provides UTF-8 support. The special cases of Linux console and screen were addressed in development patches completed at the end of 2002.