Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are there any tree libraries/widgets for (n)curses [closed]

Tags:

ncurses

curses

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

like image 348
phatmanace Avatar asked Mar 03 '10 20:03

phatmanace


2 Answers

"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;
like image 70
mrflash818 Avatar answered Sep 21 '22 06:09

mrflash818


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.

dialog - tree view

It also has a file(/directory) selection widget.

dialog - file-selection

There's also wcd (though like mc, reusability of the library is uncertain). However, it is a good example of what OP probably wants:

screenshot converted from wcd page

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:

urwid treeview

and on my Debian/testing system, the script doesn't use ncurses. It's hardcoded (i.e., using raw_display).

like image 37
Thomas Dickey Avatar answered Sep 20 '22 06:09

Thomas Dickey