Last active
September 28, 2021 17:54
-
-
Save kmarius/cf12ceba809c9dd402fdf596c2a164be to your computer and use it in GitHub Desktop.
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
// gcc input.c -lnotcurses -lnotcurses-core | |
#include <notcurses/notcurses.h> | |
#include <poll.h> | |
struct notcurses *nc; | |
struct ncplane *n; | |
int main() { | |
int ready; | |
ncinput in; | |
notcurses_options opt = {}; | |
nc = notcurses_core_init(&opt, NULL); | |
int ncols, nrows; | |
notcurses_stddim_yx(nc, &nrows, &ncols); | |
struct ncplane_options opts = { | |
.cols = ncols, | |
.rows = nrows, | |
.x = 0, | |
.y = 0, | |
}; | |
n = ncplane_create(notcurses_stdplane(nc), &opts); | |
notcurses_render(nc); | |
struct pollfd pfd = { | |
.fd = notcurses_inputready_fd(nc), | |
.events = POLLIN, | |
}; | |
while (1) { | |
ready = poll(&pfd, 1, -1); | |
if (ready == -1) | |
return 1; | |
if (pfd.revents & POLLIN) { | |
int i = 0; | |
ncplane_erase(n); | |
while (notcurses_getc_nblock(nc, &in)) { | |
ncplane_printf_yx(n, i++, 0, "%u", in.id); | |
} | |
notcurses_render(nc); | |
} | |
} | |
notcurses_stop(nc); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment