Skip to content

Instantly share code, notes, and snippets.

@kmarius
Last active September 28, 2021 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmarius/cf12ceba809c9dd402fdf596c2a164be to your computer and use it in GitHub Desktop.
Save kmarius/cf12ceba809c9dd402fdf596c2a164be to your computer and use it in GitHub Desktop.
// 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