Skip to content

Instantly share code, notes, and snippets.

@dnmfarrell
Created January 21, 2022 14:51
Show Gist options
  • Save dnmfarrell/96baa27bafcbb89f564b4529b407f891 to your computer and use it in GitHub Desktop.
Save dnmfarrell/96baa27bafcbb89f564b4529b407f891 to your computer and use it in GitHub Desktop.
Demo to read a wide character with ncurses and print it to the screen
/* wchar.c - read a wide character with ncurses and print it on the screen
* gcc -Wall $(pkg-config --cflags ncursesw) -o wchar wchar.c $(pkg-config --libs ncursesw)
* ./wchar
*/
#include <curses.h>
#include <locale.h>
int main(void)
{
setlocale(LC_ALL, "");
initscr();
cbreak();
noecho();
clear();
mvaddstr(0, 0, "Enter any character: ");
wint_t wc;
get_wch(&wc);
cchar_t cc;
setcchar(&cc, (wchar_t*)&wc, 0, 0, NULL);
add_wch(&cc);
mvaddstr(1, 0, "Press any key to quit");
getch();
endwin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment