问题
In a game project I was working on, I was seriously slowed down -- to the point of giving up -- by how there don't seem to be any libraries that can simplify the process of displaying a menu in text mode (i.e., 80x25 textbox, command.com/cmd.exe's native interface).
I need something that can give a list of choices, ideally including multiple pages, and including values to be entered to choose one of these; prompt the user; gently chide the user (perhaps ringing a bell and redrawing the "choose one:" prompt) when said user fails to enter something valid; and returning something that can be used to determine which option was passed.
This turns out to be a lot more work than it sounds like; and now, the exact same question that slowed me down so badly at home has come up (or is about to come up) at work. Does anyone know of any non-copyleft libraries with a function that can be passed a storage container of options, display them on screen, and get the user's choice?
Answer: Ncurses is very suitable for this purpose, including explicitly providing a menu driver. It has an MIT-style license, making it compatible with commercial use. However, it's not available for MS-DOS or Windows. (I'd referenced command.com above, but hadn't thought to explicitly spell out that this was a question regarding Microsoft architectures.)
However, it looks like it's been compiled successfully on DOS and Windows in the past, and I'm confident that I'll be able to get it, or at least the parts of it that I need, to work, especially given that it's the menu logic rather than line-drawing and the like that I'm after. The question Good resources for writing console style applications for Windows? should also be useful in this regard.
Later, additional answer: Windows provides a fair amount of display functionality out of the box, as depicted here -- although this does not include a menu-display system, in contrast to ncurses. An unholy hybrid of ncurses menu logic and Windows APIs? It might be as viable a choice as cygwin...
Much later additional answer: Both ncurses and pdcurses work very smoothly with Windows, even without using the Windows API for anything more than creating and sizing the display. I settled on using pdcurses, and learned to build my own menus -- allowing for callbacks, an easily expanded on-screen message queue, use of the C++ string class, and other such functionality.
Further update: Curses' menu libraries are written in C, and so work in terms of char* sequences. I gave up on trying to use them, and wrote my own menus instead, using low-level curses functions for screen display.
回答1:
Try ncurses
, it is on MIT license, which is much more permissive than GPL. It is very easy to use: menus, dialog boxes, checkboxes - it is all there. It is event-driven like most GUI libraries.
回答2:
You want ncurses. It's usually installed along with your distribution.
It can be kind of a pain, but it's the best method that I know of to get a decent "gui" in command line that isn't just type characters+enter.
回答3:
You can also check out CDK, which requires ncurses and provides windows like widgets.
来源:https://stackoverflow.com/questions/9709605/libraries-for-displaying-a-text-mode-menu