dorne/cursetree/cursetree.c

40 lines
1 KiB
C

#include <stdlib.h>
#include "ncrswrap.h"
#include "tree.h"
#include "_ncurses.h"
int ct_init(struct ct_tree **const tree) {
/* Initialise NCurses Library & Root Node */
init_ncurses();
init_tree(tree);
return EXIT_SUCCESS;
}
void ct_update(struct ct_tree *const tree) {
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->surface->win);
mvwprintw(tree->root->surface->win, 0, 0, " \r-1\n");
wrefresh(tree->root->surface->win);
return;
case KEY_RESIZE:
resize_tree(tree, termdims());
// flush ncurses virtual screen -> physical screen
doupdate();
break;
default:
wclear(tree->root->surface->win);
mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
wrefresh(tree->root->surface->win);
break;
}
}