在Linux中如何编写文本模式的图形用户界面(GUI)?

huangapple go评论108阅读模式
英文:

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:

在Linux中如何编写文本模式的图形用户界面(GUI)?

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:

答案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.

huangapple
  • 本文由 发表于 2016年2月14日 06:14:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/35385952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定