Alex Rivera | Logout

Writing a console within an application

Asked 2012-06-12T23:48:36.400
10

My application requires a console to be embeded within the application window, an example would be in a program like autoCAD where the console is at the bottom of the window waiting for commands.

enter image description here

I need the console within my application so that I can change variables and other things, so the console is not needing to be a fully blown out shell.

At the moment I have a simple console within my application, but It seems very clunky compared to a terminal(shell) which is what I want the console to be like.

enter image description here

The way that I have done it with the console I have is when the user presses the TAB key the console shows, then they can type in their command/line; Once the Return key has been pressed the string that they have typed gets parsed and the command is processed.

I am using sf::Text objects to print out text in my application window. There are a total of 5 sf::Text objects that are used, 4 for the previous commands/error messages and 1 for the current command line. When the Return key is pressed the 4th sf::Text changes its current string to the 3rd, the 3rd to the 2nd, the 2nd to the 1st and the 1st to the current command string then the current command string gets cleared and ready for input again. That way there is room for 4 'history' of commands and/or errors. Not the greatest but it was the best I could come up with. Of course the amount of history could be changed via adding more sf::Text objects. So in the end this is how I render the console to the screen

sf::RectangleShape rectangle;

rectangle.setSize(sf::Vector2f(App->getSize().x, App->getSize().y / 3));
rectangle.setPosition(0, 0);

rectangle.setFillColor(sf::Color::black);

App-
Edit
Report

1 Answer

0

Well, what you probably want if you want it to feel more like a console is:

  • Being able to switch it on and off with one button press, probably something like ~, which is used a lot.
  • Give the line you're typing on a background color, maybe transparent, but at least make sure it's not just text floating on the RenderWindow. If the output of the command is multiple lines, make sure they're all visible or that people could at least scroll through the history.
  • Make sure the commands are easy to understand and consistent. For example, if I'm not mistaken, a lot of games on the source engine use the cl_ prefix for anything rendering related. See cl_showfps 1 for example.
  • Traditional terminal input would be a nice touch. Up shows you the previous command you filled in. Maybe if you're feeling adventurous, use Tab for completion.
  • If you have some time left, a way to show available commands through --help for example would also be nice. Depending on how complicated your game is of course.

For the rest, look at how other games did this. You mentioned Quake, which has a great example of an ingame terminal. I for one think the one in a lot of Source games is also easy to use ( see Half Life 2, Counter Strike Source, Team Fortress 2, Left 4 Dead, etc. ). I don't think there are any standard libraries for this, not including another framework like OGRE or IrrLicht.

answered 2012-06-13T03:52:23.550

Your Answer