I wondered if there were any tree libraries available for (n)curses.
I'm trying to write a component that shows a tree of folders & was curious if there was a prebuilt curses component that could do this.
I've checked 'core' curses as well as libraries like CDK - and I can't seem to find anything.
If none exists, I'm not averse to building my own - but I can't seem to locate any decent tutorials on doing this, so any help in this regard would also be much appreciated.
Thanks, Ace
"I'm trying to write a component that shows a tree of folders"
CDK has the CDKFSELECT
widget.
It displays a list of directories and files, that might work for you, or the source code of CDKFSELECT might be leveraged for your own custom written solution.
CDKFSELECT *fSelect = 0;
/*
Height of zero means to extent of xterm
Width of zero means to extent of xterm
*/
int HEIGHT = 0;
int WIDTH = 0;
char *title = new char[strlen("Pick a file to open") + 1];
strcpy(title, "Pick a file to open");
char *prompt = new char[strlen("==> ") + 1];
strcpy(prompt, "==> ");
char *directoryAttribute = new char[strlen("</B>") + 1]; /* bold */
strcpy(directoryAttribute, "</B>");
char *fileAttribute = new char[strlen("</N>") + 1]; /* normal */
strcpy(fileAttribute, "</N>");
char *linkAttribute = new char[strlen("</D>") + 1]; /* dim */
strcpy(linkAttribute, "</D>");
char *sockAttribute = new char[strlen("</D>") + 1]; /* dim */
strcpy(sockAttribute, "</D>");
boolean displayBox = TRUE;
boolean displayShadow = FALSE;
fSelect = newCDKFselect(pCdkScreen,
TOP, LEFT, HEIGHT, WIDTH,
title, prompt,
A_NORMAL, '_', A_REVERSE,
directoryAttribute, fileAttribute, linkAttribute, sockAttribute,
displayBox, displayShadow);
char *filename = activateCDKFselect(fSelect, 0);
/*
2014-06-13, using DDD, filename being correctly populated
by CDK
*/
/* do other stuff... */
/*
free the memory of any dynamically created objects
that were created with new or malloc, or such
*/
destroyCDKFselect(fSelect);
delete [] title;
delete [] prompt;
delete [] directoryAttribute;
delete [] fileAttribute;
delete [] linkAttribute;
delete [] sockAttribute;
The dialog
program (which has a documented library interface) has a "tree" widget. The program works with (n)curses, and unlike CDK, is suitable for use with UTF-8.
It also has a file(/directory) selection widget.
There's also wcd
(though like mc
, reusability of the library is uncertain). However, it is a good example of what OP probably wants:
Regarding urwid
, that's debatable. Under the hood you may not actually have curses. For what it's worth, a screenshot of the treeview script:
and on my Debian/testing system, the script doesn't use ncurses. It's hardcoded (i.e., using raw_display
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With