Following is a post made by Elias Martenson some time ago. This little tidbit of information does not seem to be in the ncurses manpages, and isnt easy to find on google. I think it would be nice if it was included in or linked to by popular UTF-8 FAQ's such as Markus's one.
~~~~~~~~~~~~~~~~~~~~~
You asked about curses with wide characters.
Allow me to explain the necessary steps. If you have any questions don't hesitate to ask.
First of all, at least on my FC1 box, there are two ncurses installations. One in <ncurses/ncurses.h> and one in <ncursesw/ncurses.h> you must make sure you include the latter, or the unicode stuff will not work at all. I have absolutely no idea why this version is not the default.
You have to remember to link with -lncursesw instead of -lncurses.
Also don't forget to issue the call to setlocale(LC_ALL,"") in the beginning of the program. Although I suppose you already do. :-)
Next, you have to decide wether you want the application to work with and print wide strings (wchar_t *) or UTF-8 strings (char *). It's a matter of taste really. Both methods work and has their respective drawbacks and advantages. Usually, especially when changing existing code, it's much easier to use UTF-8. Nothing prevents you from using a combination either. Using UTF-8 most everywhere but using wchar_t where it's needed specifically.
If you want to use UTF-8, you're pretty much done! Just work with the UTF-8 strings just like any other string. Just remember to use wcslen() instead of strlen() if you want the number of characters. This is particularily important when doing formatting for a curses app.
If you want to use whcar_t, read up on the mbstowcs() and wcstombs() functions. mbs means "system encoding" pretty much (which, unless you're on a legacy system, means UTF-8). wcs is a wchar_t string. Then you can simply use addwstr() instead of addstr() etc. All of the old "char"-based functions has unicode-aware equivalents.
Well, that's it! I hope this has been of help for you.
Regards
Elias Martenson
-- Linux-UTF8: i18n of Linux on all levels Archive: http://mail.nl.linux.org/linux-utf8/
