有没有针对(n)curses 的树形库/小部件?

10

我想知道是否有任何(n)curses的树形库可用。

我正在尝试编写一个显示文件夹树的组件,并且很好奇是否有预制的curses组件可以实现这一点。

我已经检查了'core' curses以及像CDK这样的库,但似乎找不到任何东西。

如果没有,则我不反对构建自己的库-但我似乎找不到有关如何做此操作的良好教程,因此在这方面的任何帮助也将不胜感激。

4个回答

2

Urwid有一个树形小部件,顺便说一句。

更新:2020年10月1日 - 我的答案是在2010年写的,当时我为Urwid编写了一个树形小部件,因为我找不到其他的。Urwid仍然有树形小部件,但现在,我会看看Python的prompt-toolkit其中的替代方案


2
该程序(具有已记录的库接口)拥有一个“树”小部件。该程序使用(n)curses工作,并且与CDK不同,适用于UTF-8。其中dialog是一个链接。"tree"CDK也是链接。

dialog - tree view

它还有一个文件(/目录)选择小部件。

dialog - file-selection

还有wcd(虽然像mc一样,库的可重用性不确定)。但是,这是OP可能想要的一个很好的例子。

screenshot converted from wcd page

关于urwid,这是有争议的。在底层,您可能实际上并没有curses。值得一提的是,下面是treeview脚本的截图:

urwid treeview

在我的Debian/testing系统上,这个脚本没有使用ncurses,而是硬编码(即使用raw_display)。

2

我正在尝试编写一个显示文件夹树的组件。

CDK有CDKFSELECT小部件。

它显示目录和文件列表,这可能适合您,或者可以利用CDKFSELECT的源代码来编写自己的自定义解决方案。

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;

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接