英文:
How to write a text mode gui in Linux?
问题
当我编写脚本/程序时,我经常希望弹出一个简单的文本“GUI”来提示输入:
我应该如何做到这一点?例如,从Shell、Ruby、Golang或C语言。我甚至不知道这被称为什么,而且谷歌也没有回应“脚本中的文本工具”。
(示例来自Debian安装程序)。
英文:
When I write scripts/programs, often I would like to pop up a simple text 'gui' to prompt for input:
How would I do this? For example from Shell, Ruby, Golang or C. I don't even know what this is called and Google isn't reponding to "text thingy from scripts".
(The example is from the Debian installer).
答案1
得分: 8
实际上,那不是对话框,而是newt库(外观上有一些差异)。它被Red Hat系统上的anaconda使用。whiptail程序使用该库,但它与anaconda没有真正的关系。
Anaconda主要使用Python;它使用了用Python绑定编写的newt共享库。
关于学习它...文档基本上是不存在的。你可以查看源代码。
进一步阅读:
英文:
Actually, that is not dialog, but the newt library (there are a few differences in appearance). It is used by anaconda on Red Hat systems. The whiptail program uses the library, however it has no real relationship to anaconda.
Anaconda is mostly in Python; it uses the newt shared library (written in C) from a Python binding.
For learning it... documentation is largely non-existent. You have the source code.
Further reading:
- screenshots for dialog
- newt.git
- anaconda.git
- Any examples/documentation for python-newt (discussion of newt vs documentation)
- Spicing up the Console for Fun and Profit, Part 2
答案2
得分: 4
过去,这被称为“Dialog”,尽管正如Thomas指出的(作为Dialog的维护者!),现在不再是这样。这很可能是Newt库。虽然你可以使用ncurses编写更底层的代码,但Newt在Linux上几乎是普遍可用的。Dialog也可以在Linux下安装。你可以在这里阅读一些基本的文档。
选择使用这种方法而不是基于curses的方法,可以让你专注于你实际想要做的事情,而不是做所有构建UI的工作。然而,如果你真的想要构建UI元素,ncurses是一个不错的选择。
英文:
In the past this was known as "Dialog," though as Thomas points out (as the maintainer of Dialog!!) this is no longer the case. This is most likely the Newt library. While you could certainly write something lower level using ncurses, Newt is available in Linux pretty much universally. Dialog can also be installed under Linux. You can read some basic documentation for it here.
Choosing to use this over a curses based approach allows you to focus on what it is you're actually looking to do rather than doing all of the work to build a UI. If, however, you are really looking to build UI elements, ncurses would be the way to go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论