23nctree_debug_path(
const unsigned* path,
const void* pr){
24 fprintf(stderr,
"PATH ");
25 for(
const unsigned* p = path ; *p != UINT_MAX ; ++p){
26 fprintf(stderr,
"%03u ", *p);
28 fprintf(stderr,
"%p\n", pr);
32nctree_debug_internal(
const nctree_int_item* nii,
unsigned* path,
unsigned depth){
34 nctree_debug_path(path, nii->
curry);
36 for(
unsigned z = 0 ; z < nii->
subcount ; ++z){
38 path[depth + 1] = UINT_MAX;
39 nctree_debug_internal(&nii->
subs[z], path, depth + 1);
41 path[depth] = UINT_MAX;
46 unsigned* path = malloc(
sizeof(*path) * (
n->maxdepth + 2));
48 nctree_debug_internal(&
n->items, path, 0);
57 free_tree_items(&iarray->
subs[
c]);
67 unsigned count,
unsigned depth,
unsigned* maxdepth){
71 fill->
subs = malloc(
sizeof(*fill->
subs) * count);
80 free_tree_items(&fill->
subs[
c]);
86 if(dup_tree_items(nii, items[
c].subs, items[
c].subcount, depth + 1, maxdepth)){
88 free_tree_items(&fill->
subs[
c]);
94 if(depth > *maxdepth){
114 if(
n->maxdepth == 0){
115 n->currentpath[0] = UINT_MAX;
119 n->currentpath[0] = 0;
120 n->currentpath[1] = UINT_MAX;
121 n->curitem = &
n->items.subs[0];
128prep_initial_path(
nctree*
n,
unsigned maxdepth){
129 n->currentpath = malloc(
sizeof(*
n->currentpath) * (maxdepth + 2));
130 if(
n->currentpath ==
NULL){
139 nctree* ret = malloc(
sizeof(*ret));
149 if(prep_initial_path(ret, ret->
maxdepth)){
150 free_tree_items(&ret->
items);
167 const unsigned* p = spec;
168 while(p[1] != UINT_MAX){
173 nii = &nii->
subs[*p];
188 memmove(&nii->
subs[*p + 1], &nii->
subs[*p],
192 if((
unsigned)(p - spec) >=
n->maxdepth){
193 unsigned max = p - spec + 1;
194 unsigned* tmp = realloc(
n->currentpath,
sizeof(*
n->currentpath) * (max + 2));
198 n->currentpath = tmp;
199 n->currentpath[max] = UINT_MAX;
211 if(spec[0] == UINT_MAX){
223 if(nctree_add_internal(
n, &
n->items, spec, add)){
226 if(
n->activerow == -1){
228 n->curitem = &
n->items.subs[0];
229 n->currentpath = malloc(
sizeof(*
n->currentpath) * 3);
230 n->currentpath[0] = 0;
231 n->currentpath[1] = UINT_MAX;
240 const unsigned* p = spec;
241 while(*p != UINT_MAX){
247 nii = &nii->
subs[*p];
250 free_tree_items(nii);
253 unsigned lastelem = spec[-1];
255 memmove(&parent->
subs[lastelem], &parent->
subs[lastelem + 1],
259 if(
n->items.subcount == 0){
271 logerror(
"can't use the standard plane");
275 logerror(
"can't use NULL callback");
278 if(
opts->indentcols < 0){
279 logerror(
"can't indent negative columns");
284 logerror(
"couldn't prepare nctree");
296 free_tree_items(&
n->items);
297 free(
n->currentpath);
314nctree_prev_internal(
nctree*
n,
unsigned* newpath){
318 while(newpath[
idx] != UINT_MAX){
319 nii = &nii->
subs[newpath[
idx]];
323 wedge = &wedge->
subs[newpath[
idx - 1]];
330 nii = &wedge->
subs[newpath[
idx]];
335 nii = &nii->
subs[newpath[
idx]];
339 newpath[
idx] = UINT_MAX;
342 if(wedge == &
n->items){
345 newpath[
idx] = UINT_MAX;
352 rows = ncplane_dim_y(
n->curitem->ncp);
355 if(tmp !=
n->curitem){
357 n->activerow -= rows;
358 if(
n->activerow < 0){
370nctree_next_internal(
nctree*
n,
unsigned* newpath){
375 while(newpath[
idx] != UINT_MAX){
380 nii = &nii->
subs[newpath[
idx]];
385 newpath[
idx + 1] = UINT_MAX;
386 return &nii->
subs[newpath[
idx]];
390 newpath[wedidx + 1] = UINT_MAX;
391 return &wedge->
subs[newpath[wedidx]];
399 rows = ncplane_dim_y(
n->curitem->ncp);
402 if(tmp !=
n->curitem){
404 n->activerow += rows;
405 if(
n->activerow >= (
int)ncplane_dim_y(
n->items.ncp)){
406 n->activerow = ncplane_dim_y(
n->items.ncp) - 1;
413tree_path_length(
const unsigned* path){
415 while(path[
len] != UINT_MAX){
426 int* frontiert,
int* frontierb,
int distance){
428 const int startx = (tree_path_length(path) - 1) *
n->indentcols;
430 if(*frontiert == *frontierb){
432 ymax = ncplane_dim_y(
n->items.ncp) - 1;
433 }
else if(*frontiert < 0){
435 ymax = ncplane_dim_y(
n->items.ncp) - 1;
444 .cols = ncplane_dim_x(
n->items.ncp) - startx,
445 .rows = ymax - ymin + 1,
458 if(
ncplane_y(nii->
ncp) <= *frontiert || *frontierb >= (
int)ncplane_dim_y(
n->items.ncp)){
484 while((tmpnii = nctree_prev_internal(
n, path)) != nii){
490 n->cbfxn(nii->
ncp, nii->
curry, distance);
502 while((tmpnii = nctree_next_internal(
n, path)) != nii){
508 n->cbfxn(nii->
ncp, nii->
curry, distance);
517nctree_inner_redraw(
nctree*
n,
unsigned* tmppath){
518 if(
n->activerow < 0){
525 int frontiert =
n->activerow;
526 int frontierb =
n->activerow;
530 if(draw_tree_item(
n, nii, tmppath, &frontiert, &frontierb, distance)){
535 while(frontiert >= 0){
536 if((tmpnii = nctree_prev_internal(
n, tmppath)) == nii){
541 if(draw_tree_item(
n, nii, tmppath, &frontiert, &frontierb, distance)){
545 destroy_above(
n, nii, tmppath, distance);
553 memcpy(tmppath,
n->currentpath,
sizeof(*tmppath) * (
n->maxdepth + 1));
554 while(frontierb < (
int)ncplane_dim_y(
n->items.ncp)){
555 if((tmpnii = nctree_next_internal(
n, tmppath)) == nii){
560 if(draw_tree_item(
n, nii, tmppath, &frontiert, &frontierb, distance)){
564 destroy_below(
n, nii, tmppath, distance);
569 unsigned* tmppath = malloc(
sizeof(*tmppath) * (
n->maxdepth + 2));
573 memcpy(tmppath,
n->currentpath,
sizeof(*tmppath) * (
n->maxdepth + 1));
574 int ret = nctree_inner_redraw(
n, tmppath);
607 return n->curitem->curry;
#define logerror(fmt,...)
int ncplane_cursor_move_yx(ncplane *n, int y, int x)
int ncplane_x(const ncplane *n)
int ncplane_y(const ncplane *n)
ncplane * notcurses_stdplane(notcurses *nc)
int ncplane_destroy(ncplane *ncp)
int ncplane_move_yx(ncplane *n, int y, int x)
notcurses * ncplane_notcurses(const ncplane *n)
ncplane * ncplane_create(ncplane *n, const ncplane_options *nopts)
const struct ncplane_options * opts
API int API int const nccell unsigned len
struct nctree_int_item * subs
struct nctree_item * subs
int(* cbfxn)(ncplane *, void *, int)
nctree_int_item * curitem
bool nctree_offer_input(nctree *n, const ncinput *ni)
int nctree_redraw(nctree *n)
nctree * nctree_create(ncplane *n, const nctree_options *opts)
void * nctree_goto(nctree *n, const unsigned *spec, int *failspec)
ncplane * nctree_plane(nctree *n)
void nctree_destroy(nctree *n)
int nctree_add(nctree *n, const unsigned *spec, const struct nctree_item *add)
int nctree_del(nctree *n, const unsigned *spec)
void * nctree_focused(nctree *n)
void * nctree_prev(nctree *n)
void * nctree_next(nctree *n)