开发者

Is a console user interface in .net possible? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

Improve this question

I am wondering whether there are libraries in .NET that make it easy to write console user interfaces. For instance, imagine a WinForms application, where the user can:

  • Navigate the menus
  • Respond to dialogs

And the application in return displays several lines of text.

It can be shown, that the GUI in such an application can be mapped to the respective CUI without any problem.

So, if one has to stick to console, then are there any .NET tools to let write such CUI easily?

EDIT1

Let me define a constraint, which should help folks to grasp the idea of CUI. Imagine a machine, to which you can open a remote console, but not RDS. So, running a GUI application remotely on that machine is out of the question, because it will be unable to open any window. However, it is possible to have a remote console, leaving us with two possible flavors of CUI:

  • Character based graphics, like old supermarket terminals
  • Completely text based.

The first options allows to place characters at arbitrary positions on the console window. ncurses is the low level library for *nix systems that allows to do such things. A CUI created in such a way can be pretty expressive and convenient, but for the sake of our discussion let me rule this option out as well, because a remote console is unlikely to support the ability to move around the console window.

So, this leaves us with the text based CUI, the one created by means of printf and scanf only (and the likes).

EDIT2

Another clarificatio开发者_StackOverflow社区n: I mention Windows Forms in the question as an example of simple User Interface, which has nothing special that could not be translated to text based console UI. This is only to illustrate that simple GUI elements like menus and modal dialogues can be modeled in console without resorting to windows.


How about Mono Curses. http://www.mono-project.com/MonoCurses


What about Forms for Console Apps?

Alternative (aka ugly workaround) solution could be to create a web application (which will give you more flexibility over your UI) and access it with a browser which runs under DOS. That web application could be hosted on an external web server (IIS), or hosted in your console application which could also launch a DOS-based browser on start-up for user convenience.


Have a look at consolemenuui.codeplex.com. Other than menus (plus Yes-No dialogs and value prompts which should be easy to implement), I could hardly imagine other possible prompt-based controls.


A typical approach is to split your application into two parts: a backend, which can be operated via CLI, and a GUI frontend (may be more than one, e.g., web, winforms, a pure text CLI, whatever). They can communicate using a simple protocol, or a DSL - frontend asks the backend to execute commands, and the backend forces the frontend to execute commands in turn (so, the protocol must be asyncronous). If some complex visualisation is required, it is still possible to prepare it in a backend and execute in a frontent. An obvious thing to avoid doing this way is streaming video, of course.

Probably the best example of such a design is Wolfram Mathematica.

So, answering your question, you won't need any specific libraries, it is a matter of design, coding itself is trivial. The only thing you may need is a tool that will simplify your DSLs implementation. Antlr is just fine, but with C# it is easy to parse simple languages without any external parser generators.


You can try to capture/redirect the output of your own hidden console window to your applications's Windows Forms. Once you have the text you need, you can print it with PictureBox.DrawString or a similar method.

Here's more info about how to capture/redirect console output.


There's a wonderful library for handling command line options, called NDesk.Options. Being included in Mono, it is also known as Mono.Options.
It doesn't provide any additional interaction capabilities, however this is the closest I found to elegantly dealing with console from .NET app.

string data = null;
bool help   = false;
int verbose = 0;
var p = new OptionSet {
    { "file=",      v => data = v },
    { "v|verbose",  v => { ++verbose } },
    { "h|?|help",   v => help = v != null },
};

List<string> extra = p.Parse (args);

As for libraries that encapsulate console UI programming, I didn't find any, although I'd like to hear about one.


Something like this maybe?

Is a console user interface in .net possible? [closed]

I am new to C# and coding in general but grew up with a c64 and love the retro style, so I'm writing a overkill memopad/consoleprogram. It draws a menu using an array and a box around it, same goes for text files.


This is a link to a library (Console.Forms) that attempts to create a Console equivalent to System.Windows.Forms:

https://code.google.com/p/console-forms/

It is far from complete, but I think it is going in the direction you're talking about. While there are labels and a half-finished text-box, there are no menus yet. It does demonstrate opening a dialog in front of a main form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜