How would you go about coding a console?

Hey guys!

I'm working on a project of mine and I'm building a GUI for a program which itself relies on the use of a console to operate (if it makes any difference, I'm using SDL_2 for the GUI).

I'm conflicted between two ideas for the development of said condole
_Either it's going to be like your windows command, which means that it has to behave as such: you enter an input, it reads the string/int (type) and passes it to the program (for input). And it displays whatever the program needs to display on screen, taking into consideration the use of chars likes '\n', '\r','\b'.
_My second option is to tie the console to the program and make every function of the program display its data/output as a predetermined format. What's bothering me with that, is that I would have to basically rewrite the whole program so that each function has a built in display for the console, and the program is 3k + lines of code already..

I'm interested in what you think about that and maybe know what you would do, were you in my place.

Thanks for any feedback anyway, criticism is welcome!

Regards,

Hugo.


Last edited on
I would go with the second option. Having a standardized output format will probably come in really handy down the road.

And 3k lines of code really isn't that many. I bet you could go back an re-instrument your existing code base to use the standard format in a couple of hours.
So you mean to say instead of
give me time
--> Time is 2:00 am


You want
give me time
//////////////////////////////////
///current time is 2:00 am////////
//////////////////////////////////
Press "" to do "" 
Press "" to do ""

If it's just text, then whether you want to format or not is your preference.
I would go with the second option. Having a standardized output format will probably come in really handy down the road.

If by standardised you mean usable with any program then that's what I was trying to explain with my first option.



@Grime
Your examples don't speak to me sorry, I don't know what's meant to be input by the user and what's displayed by the console.


I may not have explained my two possibilities quite clear enough. To make it short and understandable:

Either I recreate a windows-ish console, that can work with any program. This would mean making the console able to interact with any C++ language that may be contained within the program's code.

Or I create a console that's part of my existing program and which would only be able to deal with the program's functions.

The difference is, in this case displaying things with the console. In the first option, the console could receive any string (or other) to output and would do so automatically. In the second option, the console could not receive any string from the program. Instead a function may display elements (strings, numbers, anything) but it would have to interact directly with the renderer and say "this goes here", "this goes 20 pixels further down" etc.

EDIT: After scratching my head more to find a way to narrow down what I mean : Either I have to replace std::cout,std::cin,std::getline etc. with my own code, or I ignore them and focus on key presses, events, and rendering positions.
Last edited on
Everything I wrote got eaten by the page when I hit that submit button.. Sigh.

Anyways I thought that each function had a separate console window. And yes my example was terrible.
'give me time' and the 'output' were supposed to be two different windows (whereas in the first example there's only one window).. but I see now what a terrible example that was..

Can I ask why Option 1 over Option 2? With Option 1 you still have to write for each function what they need to communicate with the console, whereas with Option 2 there isn't an intermediary, you're directly allowing the functions to manipulate the console.

If the question is about Option 2 being harder, then there must be some kind of GUI helper program made by somebody that can allow you to generate code, with a neat interface.

Oh or okay maybe you meant that Option 1 is to make an interface that allows you to edit the console more easily. Then yes it's sensible.
Last edited on
Can I ask why Option 1 over Option 2? With Option 1 you still have to write for each function what they need to communicate with the console, whereas with Option 2 there isn't an intermediary, you're directly allowing the functions to manipulate the console.

Well basically for option 1, for both input and output, the console is dealing with strings. The console would have a built in 'system' to handle strings i.e to print them correctly, if there is a new line char then it goes down to print what follows, if there is a tab char, then it indents automatically. Still dealing with the renderer but I would say more automatically since I don't have to manually code the positions of the output for each thing that's displayed.

Option 2 would mean that the console doesn't have any built in system that allows to render everything in its place by receiving a string. The different functions would have to tell the console, "ok you print this here, and that there".

I guess the difference between the two is whether the rendering is done automatically by the console, or if it's done manually (hardcoded) by each individual function that needs to output to the console.


then there must be some kind of GUI helper program made by somebody that can allow you to generate code, with a neat interface.

I know I can probably get an already existing code for a gui but I'd like to have 'fun' making it by myself
What issue is the console supposed to address? What does your program do?
@mbozzi

Instead of re-explaining everything, you can find a post here that does just that http://www.cplusplus.com/forum/general/248842/ :)

The console is just supposed to be a normal console, just better looking, and I may add a few features to it when it's done. Also one of the main reasons I'm making a gui is because for my program I have to rely on system("cls"), even though I'm running the 'rendering' of all I need on screen at 1 frame per second, it flickers and it's bugging me!
Topic archived. No new replies allowed.