For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2008 > curses (or ncurses) output of UTF-8 test with addchstr()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author curses (or ncurses) output of UTF-8 test with addchstr()
Nikos Chantziaras

2008-03-30, 8:17 am

In curses (or ncurses), how can I output a UTF-8 encoded char* by using
addchstr() (or any other function taking a 'chtype' as argument)?

This (obviously) won't work:

(It's C99.)


const char* utf8Str = "Some UTF-8 text here";
chtype cursesStr[SOME_SIZE];

for (size_t i = 0; i < strlen(utf8Str); ++i) {
cursesStr[i] = utf8Str[i] | A_CURSES_ATTRIBUTE_WE_WANT;
}
cursesStr[i] = 0;

addchstr(cursesStr);


I guess I would have to combine every UTF-8 multibyte sequence in
utf8Str into a single chtype and store that in cursesStr. I can't seem
to succeed in it. Is it even possible to use addchstr() and friends for
UTF-8 strings? Or would I have to convert from UTF-8 to some other
Unicode encoding? If yes, which one? If no, what are my options?
Thomas Dickey

2008-03-30, 9:09 pm

Nikos Chantziaras <realnc@arcor.de> wrote:
> In curses (or ncurses), how can I output a UTF-8 encoded char* by using
> addchstr() (or any other function taking a 'chtype' as argument)?


In ncurses, you can (assuming your locale is already using a UTF-8 encoding)
use addstr. More generally (or to pass along an attribute), you would use
setcchar, as illustrated in ncurse's test/view.c

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com