Ncurses can display characters with attached attributes via chtype
s, which are constructed by or'ing a single character with attributes bitmasks thusly :
addch('a' | A_REVERSE);
However, after enabling UTF-8 support, pushing a multibyte character to the screen must be done via addstr(char const*)
, and there is no room for attributes.
Is there a possibility of keeping attributes with multibyte characters, or should I just keep track of them myself and use attron()
/attroff()
when needed ?
There are actually four character types which can be used with ncurses:
char
(forwaddstr
)chtype
(forwaddchstr
)wchar_t
(forwaddnwstr
)cchar_t
(forwadd_wchstr
)The
char
andchtype
data came first, for 8-bit encodings.wchar_t
andcchar_t
came later for wide-characters. The latter of each pair is essentially the former combined with video attributes and color.ncurses differs from X/Open curses by allowing multibyte characters to be added via the
waddstr
(andwaddch
) interfaces. Actually this would be the "ncursesw" library (the "ncurses" library does 8-bit encodings).wchar_t
holds more bits thanchar
.On Linux,
wchar_t
is (almost) synonymous with Unicode. This is not necessarily portable, so ncurses uses the wide-character functions to convert fromwchar_t
as needed into UTF-8 — or whatever the terminal is using for its encoding. Likewise, the input towaddstr
may be UTF-8, but ncurses uses the corresponding multibyte-character functions for converting from your application's locale-encoding intowchar_t
values.