You are not logged in.
Pages: 1
Hey everyone,
I'm having a bit of an issue with understanding Allan's idea of having a single ncurses header/library(?) for both ASCII compatible and widechar text.
Since ncurses.h doesn't provide functions like add_wch/addwstr or other wide character manipulation functions, I can't seem to figure out a way to do it.
This is what I've got so far. All I want to do is find a way how to output a darn unicode checkmark.
#define _X_OPEN_SOURCE_EXTENDED
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
#include <ncurses.h>
int main(int argc, char **argv)
{
setlocale(LC_ALL, "");
initscr();
cbreak();
refresh();
mvaddch(0, 0, 'a'); // let's make sure it does output
mvaddstr(1, 0, L"\x2713"); // then let's output the checkmark
refresh();
while(1);
endwin();
return 0;
}
Can anyone provide info on how single-header ncurses handles unicode, or a short example perhaps?
Cheers,
Johnny
Last edited by developer94 (2014-06-26 08:31:20)
Offline
Thanks for the ideas!
But, if I do not use L"", I'm in for an even bigger mess. 0x2714 doesn't fit in a byte, and the compiler warns me about that aswell.
I am linking to ncursesw, so that shouldn't be an issue.
Also addwstr should be a widechar variant of addstr. I think you might be refering to waddstr which takes WINDOW* as argument.
Any other clues?
Offline
I would try encoding the check mark in utf-8, which doesn't use wide characters.
The checkmark at unicode codepoint 0x2713 would encode to the three bytes e2 9c 93 in utf-8.
Codepoint 0x2713 -> e2 9c 93
Codepoint 0x2714 -> e2 9c 94
mvaddstr(1, 0, "\xe2\x9c\x93");
see http://en.wikipedia.org/wiki/UTF-8 for more info on utf-8.
Offline
Also addwstr should be a widechar variant of addstr. I think you might be refering to waddstr which takes WINDOW* as argument.
Yeah, you are right about addwstr, the naming conventions in ncurses seems to differ from function to function.
I am linking to ncursesw, so that shouldn't be an issue.
You should use UTF8 like rockin turtle advised.
Offline
Jeeee, what was I thinking!
I went too desparate in finding a solution that I overlooked set_locale setting it to the default locale (utf-8 in my case).
Should the wiki be expanded to note this pecularity (the lack of direct widechar support in ncurses)? I could do it, but I'm new and ain't really sure how does stuff work around here.
Thanks for the help fellas!
Offline
Pages: 1