Question

From where I can start creating a console for my C++ programs ?

I need a bare minimum console to launch and manage console applications, the reason why I need this it's because I need to pack everything into 1 executable and create and control my little environment.

With the term "console" I only mean a terminal to run my program, nothing more, nothing less, I don't want my console to be interfaced with the underlaying system, only care about my console applications.

So my question is: given a C++ applications or a command line interpreter, what is the know-how required to create a terminal that is able to interface itself to this application and report and manage the usual input ( std::cout, special characters like bells, text input from the user, and so on ) ?

Was it helpful?

Solution

I think this is a WAY too large question for "one answer".

There are three components to the problem:

  1. Running another application from your code.
  2. Capturing the output of said application.
  3. Displaying the output in a console type window.

I believe at least 1 & 2 are decidedly different for each major type of platform, at the very least it is different on Windows vs. Symbian vs. Linux/Unix type platforms. I believe, largely, an Android platform can achieve this by the same method as Linux.

The third part, aside from all the complexities of emulating a VT100 or ANSI terminal (which is non-trivial because there is a large number of different escape-codes to parse and interpret, but you can probably get away with just implementing half a dozen or so to begin with).

I'd expect, aside from "platform specific code", this is a project that requires a few thousand lines of code, and if you know where to start (that is, you are familiar with fork(), execl() etc in Linux or their equivalents in another OS, and familiar with redirection if stdin, stderr and stdout using dup2() and similar functions, again with reservation for OS specific names, you could have something that roughly works in a few weeks. If you have no idea about these things, you will have to learn how to use these features first.

Of course, doing terminal emulation, such as "draw a line of text here", "insert an empty line at line X", "clear screen from this position" or "clear remaining line", etc, etc will require a fair amount of work to cover ALL the different variants and options. Especially if you wish to do this on a variable size display, rather than a "fixed 80 columns and 25 rows" as the original VT100 terminals supported. And I'm assuming you have already written code to draw basic text in OpenGL or OpenVG (does OpenVG support text natively, or do you have to do that as "draw bitmap" - I can't remember exactly how it works - I wasn't one of the people working on text in Symbian Graphics, so I was never really concerned with how it worked).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top