Make a Linux “GUI” in the command line

2020-05-23 03:21发布

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?

10条回答
\"骚年 ilove
2楼-- · 2020-05-23 03:28

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

查看更多
何必那么认真
3楼-- · 2020-05-23 03:33

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

查看更多
做个烂人
4楼-- · 2020-05-23 03:35

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.

查看更多
做个烂人
5楼-- · 2020-05-23 03:38

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

查看更多
Bombasti
6楼-- · 2020-05-23 03:39

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 :

查看更多
孤傲高冷的网名
7楼-- · 2020-05-23 03:39

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

查看更多
登录 后发表回答