是否有用于 (n)curses 的树库/小部件

发布于 2024-08-23 21:14:56 字数 1807 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

∞琼窗梦回ˉ 2024-08-30 21:14:56

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

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;

"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;
难如初 2024-08-30 21:14:56

dialog 程序(具有文档化的库接口)有一个 "tree" 小部件。该程序与 (n)curses 一起使用,与 CDK 不同,它适合与UTF-8。

dialog -树视图

它还有一个 file(/directory ) 选择小部件。

dialog - file-selection

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

从 wcd 页面转换的屏幕截图

关于urwid,这是有争议的。在幕后你可能实际上并没有诅咒。就其价值而言,treeview 脚本的屏幕截图:

urwid treeview

并且在我的 Debian/测试系统上,该脚本不使用 ncurses。它是硬编码的(即使用raw_display)。

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).

时光无声 2024-08-30 21:14:56

Urwid 有一个树形小部件,FWIW。

更新:2020-10-01 - 我在 2010 年写了我的答案,当时我为 Urwid 编写了一个树小部件,因为我找不到任何东西。 Urwid 仍然有树小部件,但这些天,我会看看 Python 的提示工具包替代方案之一

Urwid has a tree widget, FWIW.

UPDATE: 2020-10-01 - I wrote my answer back in 2010, when I wrote a tree widget for Urwid since I couldn't find anything. Urwid still has the tree widget, but these days, I would look at Python's prompt-toolkit or one of the alternatives.

上课铃就是安魂曲 2024-08-30 21:14:56

查看午夜指挥官源代码 (http://www.midnight-commander.org/)它有一个树存储小部件。

Look at the Midnight commander source code (http://www.midnight-commander.org/) It has a tree store widget.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文