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.
- Create a new console class.
Before a console can be displayed, it must be set as the
SadConsole.Global.CurrentScreen or added as a child of the
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.
var defaultConsole = new SadConsole.Console(80, 25);
The last two lines set the console we just created to the
CurrentScreen which displays it. Then, the
FocusedConsoles.Set method is called and we pass in the console we created. This lets the keyboard input work on the console.
If you want to create a console that is consistently created the same every time it is instantiated, you should create a new class type. You can hard code size, behavior settings, or even the look of the console.
This example creates a console that takes a string parameter as a title, and creates a small panel.
SadConsole.Global.CurrentScreen = new SadConsole.ScreenObject();