#include #include "ncrswrap.h" #include "tree.h" int ct_init(struct crs_tree **const tree) { /* Initialise NCurses Library & Root Node */ init_ncurses(); init_tree(tree); return EXIT_SUCCESS; } void ct_update(struct crs_tree *const tree) { struct crs_nodedims * term_dims; int term_width, term_height; const int key = wgetch(curscr); /* ncurses binds a SIGWINCH handler if SIGWINCH has SIG_DFL disposition * when initscr(3x) is called. This handler emits KEY_RESIZE (decimal 410) to stdin. * REF: manpages -> resizeterm(3x) initscr(3x) wgetch(3x) */ switch (key) { case -1: wclear(tree->root->child[0]->win); mvwprintw(tree->root->child[0]->win, 0, 0, " \r-1\n"); wrefresh(tree->root->child[0]->win); return; case KEY_RESIZE: termsize(term_width, term_height); term_dims = __alloc_dims(0, 0, term_width, term_height); resize_tree(tree, term_dims); // flush ncurses virtual screen -> physical screen doupdate(); break; default: wclear(tree->root->child[0]->win); mvwprintw(tree->root->child[0]->win, 0, 0, " \r%d\n", key); wrefresh(tree->root->child[0]->win); break; } }