Print Unicode characters in C, using ncurses

前端 未结 3 976
醉梦人生
醉梦人生 2021-01-03 04:23

I have to draw a box in C, using ncurses;

First, I have defined some values for simplicity:

#define RB \"\\e(0\\x6a\\e(B\"  (ASCII 188,Right bottom,          


        
3条回答
  •  情书的邮戳
    2021-01-03 04:55

    A few issues:

    • if your program writes something like "\e(0\x6a\e(B" using addstr, then ncurses (any curses implementation) will translate the individual characters to printable form as described in the addch manual page.
    • ncurses supports line-drawing for commonly-used pseudo-graphics using symbols (such as ACS_HLINE) which are predefined characters with the A_ALTCHARSET attribute combined. You can read about those in the Line Graphics section of the addch manual page.
    • the code 0x6a is ASCII j, which (given a VT100-style mapping) would be the lower left corner. The curses symbol for that is ACS_LRCORNER.
    • you cannot write the line-drawing characters with addstr; instead addch, addchstr are useful. There are also functions oriented to line-drawing (see box and friends).
    • running in Ubuntu, your locale encoding is probably UTF-8. To make your program work properly, it should initialize the locale as described in the Initialization section of the ncurses manual page. In particular:

      setlocale(LC_ALL, "");

      Also, your program should link against the ncursesw library (-lncursesw) to use UTF-8, rather than just ncurses (-lncurses).

    • when compiling on Ubuntu, to use the proper header definitions, you should define _GNU_SOURCE.

提交回复
热议问题