What is your actual problem? Did you encounter any errors? Your question is pretty much on par with the "how do I maek gaem?" ones. First, try to do it yourself. When you get to any errors, come here or to Stackoverflow.
You can take a look at how I did the following in Python: https://github.com/Yannbane/Pysole.
Generally, I'd suggest you make a
Console class. This class accepts user input (you'll have to be listening to it), and then translates what has been written to a function name, and then executes the function passing anything written after the name as an argument. You can have a dictionary look-up, that's what I did.
I suggest you also implement a
Command class. That class would store the function to be executed, the function's name from the console's perspective (the thing you need to write for the function to be executed), number of arguments it gets, a description, and so on. These commands can be added to the console, and I strongly suggest that you don't hardcode them, but provide a way for the user (yourself, in this case) to
console.addCommand them (or just push them to an array).
It's usually wise to have the console generate a
help command by its own, which lists all the known commands and their descriptions. All other commands should be user supplied.
All that is written or outputted (as text) also needs to be stored inside the console in a, say,
.text variable. Each frame, you just render all that text and add a background to it. Alternatively you can use some kind of markup to identify the color of a word and so on...
Other built-in commands you can have:
- description [command]
- nargs [command]
- hide (don't forget to provide another way of bringing it up once it's hidden, such as a keypress)
You will probably want to re-use this, so don't make it dependent on your game. The key of software design is code separation, so it become re-usable.
It would be great if the console knew how to draw itself, but provided a way to set things up (font, background, color) to the user, this way you achieve the above point and don't have to recode it each time.
Having a history array is very useful.
This answer is vague and from my experience, there are really tonnes of ways of doing this, I believe.