A simple console colors library for KSL, supported by the official KSL team.
The KSL colors library comes with a bunch of default colors to pick from. The
full list of colors is listed below. The library uses the colors namespace.
colors.red; // set foreground terminal color to red
colors.bright_red; // set foreground terminal color to bright red
colors.yellow; // set foreground terminal color to yellow
colors.bright_yellow; // set foreground terminal color to bright yellow
colors.green; // set foreground terminal color to green
colors.bright_green; // set foreground terminal color to bright green
colors.cyan; // set foreground terminal color to cyan
colors.bright_cyan; // set foreground terminal color to bright cyan
colors.reset; // resets terminal to default scheme
Note
More colors are likely to be added in the future. This library mainly supports the KSL compiler, so when the compiler needs new colors they'll be added here.
Below are a collection of examples, keep in mind that the terminal color will stay until explicitly reset, which is why most of these examples end with the reset string.
Show a debug message (where [DEBUG] is yellow):
io.writeln("{str}[DEBUG] {str}{str}".format(
colors.yellow,
colors.reset,
"My debug message"
));
Show a completely cyan message:
io.writeln("{str}Hello World, but in Cyan!!{str}".format(
colors.cyan,
colors.reset
));
Change the terminal foreground color to green (and don't reset it):
io.writeln("{str}".format(colors.green));
The colors library should work on all platforms. Since command prompt on Windows
doesn't support virtual terminal processing by default, the colors.init()
function contains code that will enable it. Make sure you use this if you plan
on using terminal colors on Windows (but it's probably best practice to always
call it, just in case.)
KSL colors is copyright © of kgsensei and the KSL team.