Last active
December 13, 2023 10:09
-
-
Save juniorohanyere/64c3540d2ab27bd63e3f7c9eb5b9818f to your computer and use it in GitHub Desktop.
Ncurses + Termbox
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
/* It's no joke as developers keep struggling with displaying unicode (emoji) characters on an Ncurses screen, I also faced it. | |
* After dozens of research [is it actually dozens? :)], here's what I finally came up with that brought smile to my hard research. | |
* At least time spent on research was not in vain. Yeah, so I'm making this gist for those C developers out there who are also on the struggle, | |
* and probably about to give up, but they love ncurses!! Of course, I almost gave up ncurses. Alright, the work around is below: | |
* | |
* | |
* ## C program to print emoji characters using Ncurses + Termbox | |
* | |
* **main.c** | |
*/ | |
#include <ncurses.h> | |
#include <termbox.h> | |
int main() | |
{ | |
int y, x; | |
char *hi = "Hi from here: "; | |
tb_init(); /* make sure tb_init() is called first before initscr() */ | |
initscr(); | |
noecho(); | |
SCREEN *newscreen = newterm(NULL, stdout, stdin); | |
set_term(newscreen); | |
y = getcury(stdscr); | |
x = getcurx(stdscr); | |
mvprintw(y, x, "What's up nigga: "); | |
/* Refresh the ncurses window */ | |
refresh(); | |
y = getcury(stdscr); | |
x = getcurx(stdscr); | |
tb_change_cell(x, y, 0x1F622, TB_WHITE, TB_DEFAULT); /* print a crying face */ | |
tb_present(); /* display the character (interrupt) */ | |
getch(); | |
refresh(); | |
endwin(); | |
delscreen(newscreen); | |
tb_shutdown(); | |
return 0; | |
} | |
/* | |
* | |
* compile using `gcc main.c ($ncurses6-config --clags --libs) -ltermbox -o main` | |
* | |
* here my ncurses version is ncurses 6, make sure to substitute that with your original ncurses version. | |
* Also, `libtermbox` must be installed on your system. Can be installed with: | |
* `sudo apt install libtermbox-dev` on debian based systems and most other popular distros | |
* | |
* and that's it, you should see the emoji being displayed. Mathematics solve! :) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment