dorne/cursetree/cursetree.c

57 lines
1.5 KiB
C
Raw Normal View History

2025-09-10 22:49:24 +10:00
#include <stdlib.h>
#include "ncrswrap.h"
#include "node.h"
#include "tree.h"
#include "_ncurses.h"
2025-09-10 22:49:24 +10:00
2025-09-13 11:21:34 +10:00
int ct_init(struct ct_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();
init_tree(tree);
2025-09-10 22:49:24 +10:00
return EXIT_SUCCESS;
}
/* Recursively search the tree for update requests.
*/
static void __update_rec(struct ct_node *const node) {
if (node->flags & NFLAG_RESIZE) {
/* TODO: the child has requested a resizing, but resize_node()
* TODO: wastes CPU time resizing itself!
*/
resize_node(node, dup_dims(node->surface->dims));
}
for (int i=0; i < node->cindex; i++) {
__update_rec(node->child[i]);
}
}
2025-09-13 11:21:34 +10:00
void ct_update(struct ct_tree *const tree) {
2025-09-12 01:53:20 +10:00
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);
2025-09-12 01:53:20 +10:00
return;
case KEY_RESIZE:
resize_tree(tree, termdims());
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:
// wclear(tree->root->surface->win);
mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
wrefresh(tree->root->surface->win);
2025-09-12 01:53:20 +10:00
break;
}
__update_rec(tree->root);
}