In attempting some work with ncurses I’ve come to the point where I need to use wide characters, for box drawing, but also for other stuff, and I’m in a situation where per-tile control is useful.
However, when attempting to use the following code, I get into trouble:
#define _XOPEN_SOURCE_EXTENDED
#include <locale.h>
#include <curses.h>
#include <stdlib.h>
#include <time.h>
#define ESC 27
int main() {
setlocale(LC_CTYPE, "");
initscr();
keypad(initscr(),1);
curs_set(9);
nonl();
cchar_t special;
setcchar(&special, L"æ", 0, COLOR_PAIR(0), NULL);
cchar_t speshul;
setcchar(&speshul, L"朝", 0, COLOR_PAIR(0), NULL);
int c=0;
do {
clear();
mvadd_wch(3,6, &special);
mvadd_wch(4,6,&speshul);
refresh();
} while ((ESC!=(c=getch())));
endwin();
}
Edit:
Having updated the code to use setcchar; the output is disheartening:
?
A single question mark where special should be, and nothing where speshul should be.
Neither character shows up as expected.
Where is the problem, and how can I fix it?
Edit: Some extra info in response to Petesh:
The expected result is the printing of the character “æ”, and underneath it, 朝. I’m using Terminal.app on Mac OS X; and I’m compiling it Xcode.
The devil, as it turns out, is in the details.
It turns out my problem was the call to locale:
It should read:
Setting that fixes the issue, and the characters now display correctly.