Created
January 21, 2022 14:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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