ncurseswidechar

Only some unicode characters work with ncurses


I'm using ncurses 6.3, installed on OSX 12.0.1. My program is:

#define NCURSES_WIDECHAR 1

#include <locale.h>
#include <ncurses.h>

int main() {
  setlocale(LC_ALL, "");

  initscr();
  // prints fine. Even the red heart, which is multiple code-points.
  addwstr(L"🙂❤️\n");
  // doesn't print the check mark. Interesting...
  addwstr(L"️✅");
  refresh();
  getch();
  endwin();

  // Prints fine.
  printf("%ls\n", L"✅");

  return 0;
}

I'm not sure if this is a bug in ncurses, or much more likely I am misusing it.


Solution

  • U+2705 was added to Unicode in 2010, which makes it a little old, but wcwidth returns -1, making ncurses believe it is nonprinting. I can see this in a debug trace using the ncurses test program (using mouse to select/highlight the missing character's position),

    ncurses test-program

    which has this chunk:

    PUTC 0x20
    PutAttrChar({{ {-1:\u2705} }}) at (2, 25)
    forced to blank
    PUTC 0x20
    

    The part in {{..}} comes from a trace function (see source) using _nc_wacs_width, which in turn is either a macro calling wcwidth directly, or a function calling wcwidth. Either way, it doesn't appear to be a bug in ncurses.