Make a Linux “GUI” in the command line

梦想的初衷 提交于 2020-02-26 07:02:28

问题


How to make a Linux program in the Command Line Interface who display a nice user interface?

For example when I use "wget" to download a file from internet, I can see the download advancement in the Command Line Interface. How can I do that?


回答1:


Take a look at curses. It is a library for text based UI.




回答2:


ncurses is a popular option, there are APIs for lots of programming languages.




回答3:


You can get a basic interface by using \r to go to the beginning of the current line.

Slightly more advanced is ncurses.

The next step up is Newt.




回答4:


If you want to do a GUI for Bash scripts or to wrap around other command line utilities, you can use dialog (man page).

Here two great dialog tutorial to get you started :

  • Dialog: An Introductory Tutorial
  • Improve Bash Shell Scripts Using Dialog.



回答5:


If you only need a progress bar, this can be done directly with a simple print (that prints the bar), followed by the carriage return character (ANSI character #13), which puts you back at the beginning of the line. The line can then be later updated by printing over it.

For more complicated needs, ncurses is indeed the standard way to go.




回答6:


I wouldn't call wget's progress report as a 'nice gui', but anyway, the classic library for building graphical interfaces without X Windows is Linux and UNIX systems is ncurses.

Recently a C# version of ncurses has been started, check out details here




回答7:


If you're using Mono, you could use MonoCurses




回答8:


Try curses, it is a well documented API for text based UI.Also, there is so much open source projects that are using curses for you see and learn




回答9:


wget does not really have a GUI, all I see is stuff that you can already achieve using stdout and echos (e.g. printf() or std::cout)

Anyways, for simple dialog boxes of the MessageBox kind, but not limited to that, also have a look at dialog

  • http://linux.die.net/man/1/dialog
  • http://hightek.org/dialog/



回答10:


You can just use ANSI escape codes. A simple example in bash

echo -e "\033[H\033[2J  \033[20;20H  \033[4mThis is a underlined line.\033[0m"


来源:https://stackoverflow.com/questions/2296567/make-a-linux-gui-in-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!