How to create and print on a Console
A console that you use in your program can be created in three ways:
- Create a new instance of the default console class.
- Loading a previously saved console.
- Create a new derived console class.
Before a console can be displayed, it must be as the SadConsole.Global.CurrentScreen or added as a child of the current screen.
When you create a SadConsole.Console class instance, you are getting all of the basic functionality by default. However, the console will be blank, and you will need to configure it piece-by-piece. This means that you will have to print all of the things you want on the console every time you create it. This may work well for prototyping a design of some sort, but it doesn’t really give you anything reusable.
The following example shows the basic steps to create a console that has some text on it.
Console defaultConsole = new Console(80, 25);
Saving and loading a console on the Windows platform is pretty simple. With only two lines of code, you can load and save your console. This lets you either design a console by hand, or through the SadConsole editor. The benefit of this is that you only have to design your console once, and then you can load it into multiple console instances, or just a single console instance.
The following code demonstrates how to load an entire console from a file.
Console defaultConsole = SadConsole.Console.Load("mysavedconsole.console");
If you want to create a console that is consistently created the same every time it is instantiated, you should create a newly derived type. You can hard code size, behavior settings, or even the look of the console.
This example creates a console that has a border applied to it.
BorderedConsole console = new BorderedConsole(80, 25);