Adding Unicode/UTF8 chars to a ncurses display in C

前端 未结 4 370
無奈伤痛
無奈伤痛 2020-12-06 11:09

I\'m attempting to add wchar_t Unicode characters to an ncurses display in C.

I have an array:

wchar_t characters[]={L\'\\uE030\', L\'\\uE029\'}; //          


        
相关标签:
4条回答
  • 2020-12-06 11:35

    cchar_t is defined as:

    typedef struct {
        attr_t  attr;
        wchar_t chars[CCHARW_MAX];
    } cchar_t;
    

    so you might try:

    int add_wchar(int c)
    {
        cchar_t t = {
            0, // .attr
            {c, 0} // not sure how .chars works, so best guess
        };
        return add_wch(t);
    }
    

    not at all tested, but should work.

    0 讨论(0)
  • 2020-12-06 11:36

    This is not 2 characters:

    wchar_t characters[]={L"\uE030", L"\uE029"};
    

    You're trying to initialize wchar_t (integer) values with pointers, which should result in an error from the compiler. Either use:

    wchar_t characters[]={L'\uE030', L'\uE029'};
    

    or

    wchar_t characters[]=L"\uE030\uE029";
    
    0 讨论(0)
  • 2020-12-06 11:39

    Did you define _XOPEN_SOURCE_EXTENDED before including the ncurses header?

    0 讨论(0)
  • 2020-12-06 11:56

    The wide character support is handled by ncursesw. Depending on your distro, ncurses may or may not point there (seemingly not in yours).

    Try using -lncursesw instead of -lncurses.

    Also, for the locale, try calling setlocale(LC_ALL, "")

    0 讨论(0)
提交回复
热议问题