notcurses_tree(3)
πΈ NAME πΈ
notcurses_tree β high-level hierarchical line-based data π
β¨ SYNOPSIS β¨
#include <notcurses/notcurses.h>
struct nctree;
struct ncplane;
typedef struct nctree_item {
void* curry;
struct nctree_item* subs;
unsigned subcount;
} nctree_item;
typedef struct nctree_options {
const nctree_item* items; // top-level nctree_item array
unsigned count; // size of |items|
int (*nctreecb)(struct ncplane*, void*, int); // item callback
int indentcols; // columns to indent per hierarchy
uint64_t flags; // bitfield of NCTREE_OPTION_*
} nctree_options;
struct nctree* nctree_create(struct ncplane* n, const nctree_options*
opts);
struct ncplane* nctree_plane(struct nctree* n);
int nctree_redraw(struct nctree* n);
bool nctree_offer_input(struct nctree* n, const ncinput* ni);
void* nctree_focused(struct nctree* n);
void* nctree_next(struct nctree* n);
void* nctree_prev(struct nctree* n);
void* nctree_goto(struct nctree* n, const int* path, int* failpath);
int nctree_add(struct nctree* n, const unsigned* path, const
nctree_item* add);
int nctree_del(struct nctree* n, const unsigned* path);
void nctree_destroy(struct nctree* n);
π DESCRIPTION π
okay so bestie, nctrees organize hierarchical items and let you browse them. Each item can have arbitrary subitems. Items can be collapsed and expanded. The display supports scrolling and searching. slay. π¦
Annctreecannot be empty.countmust be non-zero, anditemsmust not beNULL. The callback functionnctreecbmust also be non-NULL. no cap.
The callback function nctreecb is called on tree items when the tree is redrawn. Here's the vibe check:
- It will be called on each visible item, and any item which has become hidden.
- If the item is newly hidden, the
ncplaneargument will beNULL. - If the item is newly visible, the
ncplaneargument will be an empty plane. - If the item was already visible, the
ncplaneargument will be the same plane passed before. - If the item has not changed since the last time the callback was invoked, there is no need to change the plane, and the callback can return immediately.
- Otherwise, the plane ought be drawn by the callback. Any unused rows ought be trimmed away using
ncplane_resize. - If the plane is expanded in the callback, it will be shrunk back down by the widget.
- The
intparameter indicates distance from the focused item. If the parameter is negative, the item is before the focused item; a positive parameter implies that the item follows the focused item; the focused item itself is passed zero.
nctree_goto, nctree_add, and nctree_del all use the concept of a path. A path is an array of unsigned values, terminated by UINT_MAX, with each successive value indexing into the hierarchy thus far. The root node of the nctree thus always has a 2-element path of [0, UINT_MAX]. iykyk π
π«Ά RETURN VALUES π«Ά
nctree_createreturnsNULLfor invalid options. This includes aNULLitemsornctreecbfield, or a zerocountfield.nctree_nextandnctree_prevboth return thecurrypointer from the newly-focused item.nctree_focusedreturns thecurrypointer from the already-focused item.nctree_gotoreturns thecurrypointer from the newly-focused item. Ifpathis invalid, the first invalid hierarchy level is written tofailpath, andNULLis returned. Ifpathis valid, the value-1is written tofailpath. Since it is possible for acurrypointer to beNULL, one should checkfailpathbefore assuming the operation failed.nctree_addandnctree_delboth return-1for an invalid path, and0otherwise.
π¦ NOTES π¦
nctree shares many properties with notcurses_reel. Unlike the latter, nctrees support arbitrary hierarchical levels. π
nctree used to only handle static data, but nctree_add and nctree_del were added in Notcurses 3.0.1.
π₯ SEE ALSO π₯
π AUTHORS π
nick black nickblack@linux.com
That's the whole page, bestie β signing off from the v3.0.17 era of notcurses_tree(3) π
β¨
π¦ where this page comes from
- alpine 3.24: notcurses-doc 3.0.17-r0 Β· Apache-2.0
- ubuntu resolute: libnotcurses-core-dev 3.0.17+dfsg-3 Β· Apache-2.0
- ubuntu stonking: libnotcurses-core-dev 3.0.17+dfsg-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms