-
Notifications
You must be signed in to change notification settings - Fork 5
Quick Start Guide
Outputting text and colors is easy! Follow the steps to get an understanding of how scone functions!
When displaying things on the window, three methods must be used, namely:
clear()write(x,y,args...)print()
To give an example of a very basic application:
import scone;
void main()
{
while(true)
{
window.clear();
window.write(0,5, "hello", ' ', "world", 1);
window.print();
}
}This simple application will first clear the screen of any previous writes. This will clear all artifacts left behind. Secondly, it writes some arguments to a "buffer". Thirdly it prints everything to the window.
Now you should have basic knowledge of how an application might look like. Kudos to you π
Notes
- It is very important to understand that nothing gets written to the window until
print()is called. Neitherclear()orwrite(x,y,args...)affect the windo untilprint(). This is due to the program only changing the cells which have been modified since the lastprint()call. - This program will run forever, and the only way to exit is by force-quitting the application. This is NOT recommended, as the console/terminal might remain in an unusable state.
To display an argument in a certain color, certain parameters are required to be inputted into the write(x,y,args...) method. These parameters are as following:
- fg(color) (short for foreground)
- bg(color) (short for background)
The color taken as a parameter for these identifiers is the enum Color, which lists all ANSI default colors and their dark counterpart.
Quick introduction:
fg(Color.blue); //blue foreground color
fg(Color.blueDark); //dark blue foreground color
bg(Color.red); //red background color
bg(Color.redDark); //dark red background colorTo use these with write(x,y,args...), all arguments followed by colors will have that color. Another example:
window.write(0,0, "test1"); //will be written with default colors (fg(Color.whiteDark), bg(Color.blackDark))
window.write(0,1, fg(Color.red), "test2"); //will be red text and default background
window.write(0,2, fg(Color.red), bg(Color.white), "test3"); //will be red text and white background
window.write(0,3, bg(Color.red), "test4"); //will be default color text and red background
window.write(0,4, fg(Color.blue), "test", fg(Color.green), 5); //will be "test" in blue, and "5" in greenNow you should have an understanding of how colors are specified. Nice work π
Notes:
- Having a color as the last argument will not affect the arguments. Only colors before arguments gets applied.
Allow the user to interact with your program. This is easy!
To get input from the user, the method getInputs() needs to be called. This returns an array of the InputEvents since the last call.
A input event has the following methods:
SK key();
bool pressed();
bool hasControlKey(SCK ck);
SCK controlKey();-
key()returns the enum SK (which holds all available keys). -
pressed()returns true if the key is pressed, false if released. -
hasControlKey(ck)returns true if the current control keys are being held down. -
controlKey()returns the enum SCK, which holds all available control keys.
Please take a look at the differences between Windows and POSIX-systems, as there are some limitations to POSIX.
To give an example of how input could be retrieved:
import scone;
import std.stdio : writeln;
void main()
{
bool run = true;
while(run)
{
foreach(input; window.getInputs())
{
//NOTE: Without a ^C handler you cannot quit the program (unless you taskmanager or SIGKILL it)
//^C (Ctrl + C) or Escape
if(input.key == SK.c && input.hasControlKey(SCK.ctrl) || input.key == SK.escape)
{
run = false;
break;
}
writeln(input.key, ", ", input.controlKey, ", ", input.pressed);
}
}
}Now you know how to retrieve inputs from the user! Great π
Notes:
- For POSIX, keep to simple ASCII characters (
a-Z,0-9) for best results.