CPPConsole
Loading...
Searching...
No Matches
console Namespace Reference

Namespace Containing all console commands. More...

Data Structures

struct  ConsoleCoord
 A position on the console (row and column) More...
 
struct  Dimensions
 A structure representing the dimensions of the console. More...
 
struct  is_map
 Template for a map-like data type. Matches things like map and unordered_map. More...
 
struct  is_not_string
 
struct  iterable
 Template for a iterable data type. Matches things like vector, deque, map, etc. More...
 

Enumerations

enum  Graphics {
  BOLD = 1 , DIM , ITALIC , UNDERLINE ,
  BLINK , INVERT , HIDDEN , STRIKETHROUGH ,
  BLACK = 30 , RED , GREEN , YELLOW ,
  BLUE , MAGENTA , CYAN , WHITE ,
  DEFAULT = 39 , BG_BLACK = 40 , BG_RED , BG_GREEN ,
  BG_YELLOW , BG_BLUE , BG_MAGENTA , BG_CYAN ,
  BG_WHITE , BG_DEFAULT = 49 , BRIGHT_BLACK = 90 , BRIGHT_RED ,
  BRIGHT_GREEN , BRIGHT_YELLOW , BRIGHT_BLUE , BRIGHT_MAGENTA ,
  BRIGHT_CYAN , BRIGHT_WHITE , BG_BRIGHT_BLACK = 100 , BG_BRIGHT_RED ,
  BG_BRIGHT_GREEN , BG_BRIGHT_YELLOW , BG_BRIGHT_BLUE , BG_BRIGHT_MAGENTA ,
  BG_BRIGHT_CYAN , BG_BRIGHT_WHITE
}
 Enumeration of builtin colors for ANSI escape codes, along with other graphics modes. More...
 

Functions

bool isANSIEnabled ()
 Checks if ANSI Codes are enable in windows.
 
void enableANSI ()
 Enables ANSI for Windows environments.
 
std::string colorize (const std::string &str, Graphics color)
 Colors the text color to a predefined color.
 
std::string colorize (const std::string &str, unsigned char color, bool foreground=true)
 Colors the text color to a custom color, between 0 to 255.
 
std::string colorize (const std::string &str, unsigned char r, unsigned char g, unsigned char b, bool foreground=true)
 Colors the text color to a custom RGB color.
 
void setColor (Graphics color)
 Sets the color of the text to a predefined color.
 
void setColor (unsigned char color, bool foreground=true)
 Sets the color of the text to a custom color, between 0 to 255.
 
void setColor (unsigned char r, unsigned char g, unsigned char b, bool foreground=true)
 Sets the color of the text to a custom RGB color.
 
template<typename T >
void print (const T &value)
 Prints out a value.
 
template<typename T , size_t N, typename std::enable_if_t< is_not_string< T >::value, int > = 0>
void print (const T(&arr)[N])
 Prints out the values of an array.
 
template<size_t N>
void print (const char(&arr)[N])
 Prints out a char array.
 
void print (const std::string &str)
 Prints out a string.
 
void print ()
 
template<typename T >
void println (const T &value)
 Prints out an object, then a newline.
 
void println ()
 Prints out a newline.
 
ConsoleCoord getCursorPosition ()
 Gets the position of the cursor within the console.
 
void moveCursorHome ()
 Moves cursor to home position (0, 0)
 
void moveCursorToPosition (int row, int col)
 Move the cursor to the specified position in the console.
 
void moveCursorUp (int n)
 Move the cursor up by n lines.
 
void moveCursorDown (int n)
 Move the cursor down by n lines.
 
void moveCursorRight (int n)
 Move the cursor right by n lines.
 
void moveCursorLeft (int n)
 Move the cursor left by n lines.
 
void moveCursorDownAndToStart (int n)
 Moves cursor to beginning of next line, n lines down.
 
void moveCursorUpAndToStart (int n)
 Moves cursor to beginning of previous line, n lines up.
 
void moveCursorToColumn (int n)
 Moves cursor to column n.
 
Dimensions getDimensions ()
 Gets the width and height of the console.
 
void eraseFromCursorToEOS ()
 Erases the screen from the cursor to the end of screen.
 
void eraseFromCursorToBOS ()
 Erases the screen from the cursor to the beginning of screen.
 
void eraseEntireScreen ()
 Erases the entire screen.
 
void eraseFromCursorToEOL ()
 Erases from the cursor position to the end of the line.
 
void eraseFromCursorToBOL ()
 Erases from the cursor position to the beginning of the line.
 
void eraseCurrentLine ()
 Erases the line the cursor is currently on.
 
std::string bold (const std::string &str)
 Returns a bolded string if ANSI is enabled.
 
std::string faint (const std::string &str)
 Returns a faint/dim string if ANSI is enabled.
 
std::string italic (const std::string &str)
 Returns an italicized string if ANSI is enabled.
 
std::string underline (const std::string &str)
 Returns an underlined string if ANSI is enabled.
 
std::string blink (const std::string &str)
 Returns a blinking string if ANSI is enabled.
 
std::string inverse (const std::string &str)
 Returns a inversed/reversed string if ANSI is enabled.
 
std::string hidden (const std::string &str)
 Returns a hidden string if ANSI is enabled.
 
std::string strikethrough (const std::string &str)
 Returns a strikethough string if ANSI is enabled.
 
void setBold (bool set)
 Sets the text to be bold or not.
 
void setFaint (bool set)
 Sets the text to be faint/dim or not.
 
void setItalic (bool set)
 Sets the text to be italicized or not.
 
void setUnderline (bool set)
 Sets the text to be underlined or not.
 
void setBlink (bool set)
 Sets the text to be blinking or not.
 
void setInverse (bool set)
 Sets the text to be inversed/reversed or not.
 
void setHidden (bool set)
 Sets the text to be hidden or not.
 
void setStrikethrough (bool set)
 Sets the text to be strikethrough or not.
 
void set (std::initializer_list< Graphics > list)
 
std::string set (const std::string &str, std::initializer_list< Graphics > list)
 
void clearGraphics ()
 
template<typename T >
void printAll (T t)
 
template<typename T , typename... Args>
void printAll (T t, Args... args)
 Prints all items, with a space inbetween.
 
template<typename T >
void printlnAll (T t)
 
template<typename T , typename... Args>
void printlnAll (T t, Args... args)
 Prints all items.
 

Detailed Description

Namespace Containing all console commands.

Enumeration Type Documentation

◆ Graphics

enum Graphics

Enumeration of builtin colors for ANSI escape codes, along with other graphics modes.

Enumerator
BOLD 
DIM 
ITALIC 
UNDERLINE 
BLINK 
INVERT 
HIDDEN 
STRIKETHROUGH 
BLACK 
RED 
GREEN 
YELLOW 
BLUE 
MAGENTA 
CYAN 
WHITE 
DEFAULT 
BG_BLACK 
BG_RED 
BG_GREEN 
BG_YELLOW 
BG_BLUE 
BG_MAGENTA 
BG_CYAN 
BG_WHITE 
BG_DEFAULT 
BRIGHT_BLACK 
BRIGHT_RED 
BRIGHT_GREEN 
BRIGHT_YELLOW 
BRIGHT_BLUE 
BRIGHT_MAGENTA 
BRIGHT_CYAN 
BRIGHT_WHITE 
BG_BRIGHT_BLACK 
BG_BRIGHT_RED 
BG_BRIGHT_GREEN 
BG_BRIGHT_YELLOW 
BG_BRIGHT_BLUE 
BG_BRIGHT_MAGENTA 
BG_BRIGHT_CYAN 
BG_BRIGHT_WHITE 

Function Documentation

◆ blink()

std::string blink ( const std::string &  str)

Returns a blinking string if ANSI is enabled.

◆ bold()

std::string bold ( const std::string &  str)

Returns a bolded string if ANSI is enabled.

◆ clearGraphics()

void clearGraphics ( )

◆ colorize() [1/3]

std::string colorize ( const std::string &  str,
Graphics  color 
)

Colors the text color to a predefined color.

Parameters
colorThe color to set the text to

◆ colorize() [2/3]

std::string colorize ( const std::string &  str,
unsigned char  color,
bool  foreground = true 
)

Colors the text color to a custom color, between 0 to 255.

From 0 to 15, the colors are the standard ANSI colors From 16 to 231, the color uses the forumla 16 + (R × 36) + (G × 6) + B From 232 to 255, the colors are grayscale

Parameters
colorColor to set the text to
foregroundWhether to set the foreground or background color (default is foreground)

◆ colorize() [3/3]

std::string colorize ( const std::string &  str,
unsigned char  r,
unsigned char  g,
unsigned char  b,
bool  foreground = true 
)

Colors the text color to a custom RGB color.

Parameters
strThe string to colorize
rRed value (0-255)
gGreen value (0-255)
bBlue value (0-255)
foregroundWhether to set the foreground or background color (default is foreground)

◆ enableANSI()

void enableANSI ( )

Enables ANSI for Windows environments.

◆ eraseCurrentLine()

void eraseCurrentLine ( )

Erases the line the cursor is currently on.

◆ eraseEntireScreen()

void eraseEntireScreen ( )

Erases the entire screen.

◆ eraseFromCursorToBOL()

void eraseFromCursorToBOL ( )

Erases from the cursor position to the beginning of the line.

◆ eraseFromCursorToBOS()

void eraseFromCursorToBOS ( )

Erases the screen from the cursor to the beginning of screen.

◆ eraseFromCursorToEOL()

void eraseFromCursorToEOL ( )

Erases from the cursor position to the end of the line.

◆ eraseFromCursorToEOS()

void eraseFromCursorToEOS ( )

Erases the screen from the cursor to the end of screen.

◆ faint()

std::string faint ( const std::string &  str)

Returns a faint/dim string if ANSI is enabled.

◆ getCursorPosition()

ConsoleCoord getCursorPosition ( )

Gets the position of the cursor within the console.

Returns
The row, col position within the console

◆ getDimensions()

Dimensions getDimensions ( )

Gets the width and height of the console.

Returns
A struct containing the width and height of the console

◆ hidden()

std::string hidden ( const std::string &  str)

Returns a hidden string if ANSI is enabled.

◆ inverse()

std::string inverse ( const std::string &  str)

Returns a inversed/reversed string if ANSI is enabled.

◆ isANSIEnabled()

bool isANSIEnabled ( )

Checks if ANSI Codes are enable in windows.

Returns
True, if enabled, false if not. Always returns true on Linux systems

◆ italic()

std::string italic ( const std::string &  str)

Returns an italicized string if ANSI is enabled.

◆ moveCursorDown()

void moveCursorDown ( int  n)

Move the cursor down by n lines.

Parameters
nNumber of lines to move by.

◆ moveCursorDownAndToStart()

void moveCursorDownAndToStart ( int  n)

Moves cursor to beginning of next line, n lines down.

Parameters
nNumber of lines to move by.

◆ moveCursorHome()

void moveCursorHome ( )

Moves cursor to home position (0, 0)

◆ moveCursorLeft()

void moveCursorLeft ( int  n)

Move the cursor left by n lines.

Parameters
nNumber of lines to move by.

◆ moveCursorRight()

void moveCursorRight ( int  n)

Move the cursor right by n lines.

Parameters
nNumber of lines to move by.

◆ moveCursorToColumn()

void moveCursorToColumn ( int  n)

Moves cursor to column n.

Parameters
nColumn to move to

◆ moveCursorToPosition()

void moveCursorToPosition ( int  row,
int  col 
)

Move the cursor to the specified position in the console.

Parameters
rowRow to move to
colColumn to move to

◆ moveCursorUp()

void moveCursorUp ( int  n)

Move the cursor up by n lines.

Parameters
nNumber of lines to move by.

◆ moveCursorUpAndToStart()

void moveCursorUpAndToStart ( int  n)

Moves cursor to beginning of previous line, n lines up.

Parameters
nNumber of lines to move by.

◆ print() [1/5]

void print ( )

◆ print() [2/5]

template<size_t N>
void print ( const char(&)  arr[N])

Prints out a char array.

Template Parameters
NSize of array
Parameters
arrThe array

◆ print() [3/5]

void print ( const std::string &  str)

Prints out a string.

Parameters
strThe string to print

◆ print() [4/5]

template<typename T >
void print ( const T &  value)

Prints out a value.

Template Parameters
TType of the value
Parameters
valueThe item to print

◆ print() [5/5]

template<typename T , size_t N, typename std::enable_if_t< is_not_string< T >::value, int > = 0>
void print ( const T(&)  arr[N])

Prints out the values of an array.

Template Parameters
TType of the array
NLength of the array
Parameters
arrThe array

◆ printAll() [1/2]

template<typename T >
void printAll ( t)

◆ printAll() [2/2]

template<typename T , typename... Args>
void printAll ( t,
Args...  args 
)

Prints all items, with a space inbetween.

Parameters
argsItems to print

◆ println() [1/2]

void println ( )

Prints out a newline.

◆ println() [2/2]

template<typename T >
void println ( const T &  value)

Prints out an object, then a newline.

Template Parameters
TType of the item passed in
Parameters
valueValue to print

◆ printlnAll() [1/2]

template<typename T >
void printlnAll ( t)

◆ printlnAll() [2/2]

template<typename T , typename... Args>
void printlnAll ( t,
Args...  args 
)

Prints all items.

Parameters
argsItems to print

◆ set() [1/2]

std::string set ( const std::string &  str,
std::initializer_list< Graphics list 
)

◆ set() [2/2]

void set ( std::initializer_list< Graphics list)

◆ setBlink()

void setBlink ( bool  set)

Sets the text to be blinking or not.

Parameters
setEnable/Disable blinking text

◆ setBold()

void setBold ( bool  set)

Sets the text to be bold or not.

Parameters
setEnable/Disable bold text

◆ setColor() [1/3]

void setColor ( Graphics  color)

Sets the color of the text to a predefined color.

Parameters
colorThe color to set the text to

◆ setColor() [2/3]

void setColor ( unsigned char  color,
bool  foreground = true 
)

Sets the color of the text to a custom color, between 0 to 255.

From 0 to 15, the colors are the standard ANSI colors From 16 to 231, the color uses the forumla 16 + (R × 36) + (G × 6) + B From 232 to 255, the colors are grayscale

Parameters
colorColor to set the text to
foregroundWhether to set the foreground or background color (default is foreground)

◆ setColor() [3/3]

void setColor ( unsigned char  r,
unsigned char  g,
unsigned char  b,
bool  foreground = true 
)

Sets the color of the text to a custom RGB color.

Parameters
colorThe color to set the text to
foregroundWhether to set the foreground or background color (default is foreground)

◆ setFaint()

void setFaint ( bool  set)

Sets the text to be faint/dim or not.

Parameters
setEnable/Disable faint/dim text

◆ setHidden()

void setHidden ( bool  set)

Sets the text to be hidden or not.

Parameters
setEnable/Disable hidden text

◆ setInverse()

void setInverse ( bool  set)

Sets the text to be inversed/reversed or not.

Parameters
setEnable/Disable inversed/reversed text

◆ setItalic()

void setItalic ( bool  set)

Sets the text to be italicized or not.

Parameters
setEnable/Disable italicized text

◆ setStrikethrough()

void setStrikethrough ( bool  set)

Sets the text to be strikethrough or not.

Parameters
setEnable/Disable strikethrough text

◆ setUnderline()

void setUnderline ( bool  set)

Sets the text to be underlined or not.

Parameters
setEnable/Disable underlined text

◆ strikethrough()

std::string strikethrough ( const std::string &  str)

Returns a strikethough string if ANSI is enabled.

◆ underline()

std::string underline ( const std::string &  str)

Returns an underlined string if ANSI is enabled.