ASL
Loading...
Searching...
No Matches
Console Class Reference

Detailed Description

Helper class to control the text console, change output text color and cursor position.

Console console;
console.clear();
console.gotoxy(10, 5);
console.color(Console::BRED); // bright red
console.bgcolor(Console::GREEN);
cout << "Warning: " << warn_message << endl;
console.reset();
An Array is a contiguous and resizable array of any type of elements.
Definition Array.h:69
Helper class to control the text console, change output text color and cursor position.
Definition Console.h:56
void bgcolor(Color color=DEFAULT)
Sets the current output background color.
void color(Color color=DEFAULT)
Sets the current text output color, or if no argument is given, the color will be the default termina...
void clear()
Clear the console.
void reset()
Resets attributes to defaults.
void gotoxy(int x, int y)
Sets the cursor position to coordinates x, y

In modern consoles, color can be set as RGB components:

console.gotoxy(10, 5);
console.bgcolor(255, 10, 10);
cout << "Text on red";

If many different colors are to be printed in sequence, better performance is achieved by forming a string with all color-changing terminal codes followed by the text, and then printing this string.

console.setColorMode(2); // use mode 1 for older consoles not supporting full color
console.gotoxy(10, 5);
s << console.bg() << console.rgb(255, 10, 10) << "Red ";
s << console.bg() << console.rgb(10, 50, 215) << "blue.";
printf("%s\n", *s);
String bg() const
Returns the prefix code to set a background color.
Definition Console.h:128
void setColorMode(int mode)
Sets color mode: 1=256 colors (RGB 6x6x6), 2=true color (RGB 24bit) for RGB color setting functions (...
Definition Console.h:102
String rgb(int r, int g, int b) const
Returns terminal code to set an RGB color (or the closest if full RGB is not supported)
String represents a character string that behaves similarly to JavaScript strings in that it can be c...
Definition String.h:126

_(This is still work in progress)_

#include <Console.h>

Public Types

enum  Color
 Colors for text or background, there are normal and bright/bold versions (prefixed by a B): RED, GREEN, BLUE, WHITE, MAGENTA, CYAN, YELLOW, BLACK, BRIGHT, BRED, BGREEN, BBLUE, BWHITE, BMAGENTA, BCYAN, BYELLOW, BBLACK
 

Public Member Functions

void setCP (int cp=0, bool loc=false)
 On Windows, sets the console output code page (if 0 given, uses the system code page, if -1 uses the default console page), and if loc is true sets the locale for string case management to the system locale.
 
void gotoxy (int x, int y)
 Sets the cursor position to coordinates x, y
 
void clear ()
 Clear the console.
 
void setColorMode (int mode)
 Sets color mode: 1=256 colors (RGB 6x6x6), 2=true color (RGB 24bit) for RGB color setting functions (only for relatively modern consoles)
 
void color (Color color=DEFAULT)
 Sets the current text output color, or if no argument is given, the color will be the default terminal text color.
 
void bgcolor (Color color=DEFAULT)
 Sets the current output background color.
 
void color (int r, int g, int b)
 Sets current text color as RGB (if supported)
 
void bgcolor (int r, int g, int b)
 Sets current text color as RGB (if supported)
 
String bg () const
 Returns the prefix code to set a background color.
 
String fg () const
 Returns the prefix code to set a foreground color.
 
String rgb (int r, int g, int b) const
 Returns terminal code to set an RGB color (or the closest if full RGB is not supported)
 
void inverse (bool on=true)
 Reverses text and background colors.
 
void showCursor (bool on)
 Shows or hides the cursor.
 
void reset ()
 Resets attributes to defaults.
 
Size size ()
 Returns the size of the console window in characters {width, height}.
 

Member Function Documentation

◆ setCP()

void setCP ( int  cp = 0,
bool  loc = false 
)

On Windows, sets the console output code page (if 0 given, uses the system code page, if -1 uses the default console page), and if loc is true sets the locale for string case management to the system locale.

(this behavior might change in the future)


The documentation for this class was generated from the following file: