2025-09-10 22:49:24 +10:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2025-09-13 10:58:31 +10:00
|
|
|
#include "ncrswrap.h"
|
2025-09-13 11:16:28 +10:00
|
|
|
#include "tree.h"
|
2025-09-10 22:49:24 +10:00
|
|
|
|
2025-09-12 00:17:48 +10:00
|
|
|
int ct_init(struct crs_tree **const tree) {
|
2025-09-11 21:12:40 +10:00
|
|
|
/* Initialise NCurses Library & Root Node */
|
2025-09-11 17:41:14 +10:00
|
|
|
init_ncurses();
|
2025-09-13 11:16:28 +10:00
|
|
|
init_tree(tree);
|
2025-09-10 22:49:24 +10:00
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 00:17:48 +10:00
|
|
|
|
|
|
|
|
void ct_update(struct crs_tree *const tree) {
|
2025-09-12 01:53:20 +10:00
|
|
|
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:
|
2025-09-13 10:39:58 +10:00
|
|
|
wclear(tree->root->child[0]->win);
|
|
|
|
|
mvwprintw(tree->root->child[0]->win, 0, 0, " \r-1\n");
|
|
|
|
|
wrefresh(tree->root->child[0]->win);
|
2025-09-12 01:53:20 +10:00
|
|
|
return;
|
|
|
|
|
case KEY_RESIZE:
|
|
|
|
|
termsize(term_width, term_height);
|
2025-09-12 00:17:48 +10:00
|
|
|
term_dims = __alloc_dims(0, 0, term_width, term_height);
|
|
|
|
|
resize_tree(tree, term_dims);
|
2025-09-12 01:53:20 +10:00
|
|
|
// flush ncurses virtual screen -> physical screen
|
|
|
|
|
doupdate();
|
2025-09-13 10:39:58 +10:00
|
|
|
break;
|
2025-09-12 01:53:20 +10:00
|
|
|
default:
|
2025-09-13 10:39:58 +10:00
|
|
|
wclear(tree->root->child[0]->win);
|
|
|
|
|
mvwprintw(tree->root->child[0]->win, 0, 0, " \r%d\n", key);
|
|
|
|
|
wrefresh(tree->root->child[0]->win);
|
2025-09-12 01:53:20 +10:00
|
|
|
break;
|
2025-09-12 00:17:48 +10:00
|
|
|
}
|
|
|
|
|
}
|