CIOF v1.2.0-build
Char Input Output Format - A simple Input and Output utility library
Loading...
Searching...
No Matches
ciof Namespace Reference

Namespaces

namespace  impl
 Implementation functions.

Classes

struct  CIOFOutputConfig
 Set output configuration for ciof::impl::__out() function and its wrappers. More...

Typedefs

typedef struct ciof::CIOFOutputConfig CIOFOutputConfig
 Set output configuration for ciof::impl::__out() function and its wrappers.

Enumerations

enum class  OutputStyle { Bold , Italic , Underline , Strikethrough }
 Set output style: Bold Italic Underline Strikethrough. More...
enum class  OutputType { Out , Err , Log }
 Set output type for ciof::impl::__out() function and its helper functions Out : To Standard Output Err : To Standard Error Log : To Standard Log (Error, unbuffered). More...

Functions

void clear ()
 Clear the contents of the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().
std::string colorSet (int _color)
 Set the colors from the default color palette from the terminal.
void cursorPos (int _row, int _col)
 Get the set cursor position using _row and _col Essentially calls the getCursorPos() function and then sets the row and col according to the getCursorPos() function.
template<typename T>
void echo (T _t)
 Echo to the standard output for _t.
template<typename T, typename ... Args>
void echo (T _t, Args ... _args)
 Echo to the standard output for _t.
template<typename T>
void echoError (T _t)
 Echo to the standard error for _t.
template<typename T, typename ... Args>
void echoError (T _t, Args ... _args)
 Echo to the standard log for _t.
template<typename T>
void echoLog (T _t)
 Echo to the standard log for _t.
template<typename T, typename ... Args>
void echoLog (T _t, Args ... _args)
 Echo to the standard log for _t.
template<typename T, typename ... Args>
std::string format (T _t, Args ... _args)
 Get everything as a string format.
std::string getCursorPos (int _row, int _col)
 Get the set cursor position using _row and _col.
void initANSI ()
 Initialize ANSI text option in Windows 10 or later NOTE: ONLY WORKS IN WINDOWS 10 OR LATER.
void input ()
 Empty input() function; Do not save any input to a variable, just leave it as a blank input.
template<typename T>
void input (const std::string &_prompt, T *_var)
 Get full input from the user with a prompt.
template<typename T>
void input (T *_var)
 Get full input from the user.
void print ()
 Print a new line.
template<typename T>
void print (T _t)
 Print to the standard output for _t.
template<typename T, typename ... Args>
void print (T _t, Args ... _args)
 Print to the standard output for _t.
template<typename T>
void printError (T _t)
 Print to the standard error for _t.
template<typename T, typename ... Args>
void printError (T _t, Args ... _args)
 Print to the standard error for _t.
template<typename T>
void printLog (T _t)
 Print to the standard log for _t.
template<typename T, typename ... Args>
void printLog (T _t, Args ... _args)
 Print to the standard log for _t.
std::string rgbBgSet (unsigned int r, unsigned int g, unsigned int b)
 Set the RGB color for background in the terminal.
std::string rgbSet (unsigned int r, unsigned int g, unsigned int b)
 Set the RGB color in the terminal.
void showCursor (const bool &show)
 Show or hide the cursor from the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().
std::string styleReset ()
 Reset all the styles and colors in the terminal.
std::string styleSet (const OutputStyle &_style)
 Set the styles according to the OutputStyle type.

Variables

CIOFOutputConfig outputConf
 Set default output configuration.

Typedef Documentation

◆ CIOFOutputConfig

typedef struct ciof::CIOFOutputConfig ciof::CIOFOutputConfig

Set output configuration for ciof::impl::__out() function and its wrappers.

Enumeration Type Documentation

◆ OutputStyle

enum class ciof::OutputStyle
strong

Set output style: Bold Italic Underline Strikethrough.

Enumerator
Bold 
Italic 
Underline 
Strikethrough 

Definition at line 58 of file ciof.hpp.

◆ OutputType

enum class ciof::OutputType
strong

Set output type for ciof::impl::__out() function and its helper functions Out : To Standard Output Err : To Standard Error Log : To Standard Log (Error, unbuffered).

Enumerator
Out 
Err 
Log 

Definition at line 44 of file ciof.hpp.

45 {
46 Out, // std::cout
47 Err, // std::cerr
48 Log, // std::clog
49 };

Function Documentation

◆ clear()

void ciof::clear ( )

Clear the contents of the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().

Definition at line 64 of file ciof.cpp.

65 { ciof::echo("\033[2J\033[H"); }
void echo(T _t)
Echo to the standard output for _t.

References echo().

◆ colorSet()

std::string ciof::colorSet ( int _color)

Set the colors from the default color palette from the terminal.

Parameters
_colorInteger for color
Returns
std::string Escape code to set the code

Definition at line 76 of file ciof.cpp.

77 { return "\033[" + std::to_string(_color) + "m"; }

◆ cursorPos()

void ciof::cursorPos ( int _row,
int _col )

Get the set cursor position using _row and _col Essentially calls the getCursorPos() function and then sets the row and col according to the getCursorPos() function.

Parameters
_rowRow to set (X)
_colColumn to set (Y)

Definition at line 31 of file ciof.cpp.

32 { std::cout << getCursorPos(_row, _col) << std::flush; }
std::string getCursorPos(int _row, int _col)
Get the set cursor position using _row and _col.
Definition ciof.cpp:28

References getCursorPos().

◆ echo() [1/2]

template<typename T>
void ciof::echo ( T _t)

Echo to the standard output for _t.

Parameters
_tMessage to print

Referenced by clear(), and showCursor().

◆ echo() [2/2]

template<typename T, typename ... Args>
void ciof::echo ( T _t,
Args ... _args )

Echo to the standard output for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ echoError() [1/2]

template<typename T>
void ciof::echoError ( T _t)

Echo to the standard error for _t.

Parameters
_tMessage to print

◆ echoError() [2/2]

template<typename T, typename ... Args>
void ciof::echoError ( T _t,
Args ... _args )

Echo to the standard log for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ echoLog() [1/2]

template<typename T>
void ciof::echoLog ( T _t)

Echo to the standard log for _t.

Parameters
_tMessage to print

◆ echoLog() [2/2]

template<typename T, typename ... Args>
void ciof::echoLog ( T _t,
Args ... _args )

Echo to the standard log for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ format()

template<typename T, typename ... Args>
std::string ciof::format ( T _t,
Args ... _args )

Get everything as a string format.

Parameters
_tFirst param of the string
_argsRest of the params of the string
Returns
std::string Return the formatted string

◆ getCursorPos()

std::string ciof::getCursorPos ( int _row,
int _col )

Get the set cursor position using _row and _col.

Parameters
_rowRow to set (X)
_colColumn to set (Y)
Returns
std::string Return the string to set the position using ANSI

Definition at line 28 of file ciof.cpp.

29 { return std::string("\033[" + std::to_string(_row) + ";" + std::to_string(_col) + "H"); }

Referenced by cursorPos().

◆ initANSI()

void ciof::initANSI ( )

Initialize ANSI text option in Windows 10 or later NOTE: ONLY WORKS IN WINDOWS 10 OR LATER.

Definition at line 34 of file ciof.cpp.

35 {
36# ifdef CIOF_OS_WIN32
37 // NOTE:
38 // This must ONLY be used in Windows 10 or newer
39 if (!IsWindows10OrGreater()) return;
40
41 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
42 DWORD dwMode = 0;
43
44 GetConsoleMode(hOut, &dwMode);
45
46 dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
47
48 SetConsoleMode(hOut, dwMode);
49# endif
50 }

◆ input() [1/3]

void ciof::input ( )

Empty input() function; Do not save any input to a variable, just leave it as a blank input.

Definition at line 21 of file ciof.cpp.

22 {
23 std::string empty;
24
25 ciof::input(&empty);
26 }
void input()
Empty input() function; Do not save any input to a variable, just leave it as a blank input.
Definition ciof.cpp:21

References input().

Referenced by input().

◆ input() [2/3]

template<typename T>
void ciof::input ( const std::string & _prompt,
T * _var )

Get full input from the user with a prompt.

Parameters
_promptPrompt to user
_varVariable to store the value

◆ input() [3/3]

template<typename T>
void ciof::input ( T * _var)

Get full input from the user.

Parameters
_promptPrompt to user
_varVariable to store the value

◆ print() [1/3]

void ciof::print ( )

Print a new line.

Definition at line 18 of file ciof.cpp.

19 { std::cout << std::endl; }

◆ print() [2/3]

template<typename T>
void ciof::print ( T _t)

Print to the standard output for _t.

Parameters
_tMessage to print

◆ print() [3/3]

template<typename T, typename ... Args>
void ciof::print ( T _t,
Args ... _args )

Print to the standard output for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ printError() [1/2]

template<typename T>
void ciof::printError ( T _t)

Print to the standard error for _t.

Parameters
_tMessage to print

◆ printError() [2/2]

template<typename T, typename ... Args>
void ciof::printError ( T _t,
Args ... _args )

Print to the standard error for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ printLog() [1/2]

template<typename T>
void ciof::printLog ( T _t)

Print to the standard log for _t.

Parameters
_tMessage to print

◆ printLog() [2/2]

template<typename T, typename ... Args>
void ciof::printLog ( T _t,
Args ... _args )

Print to the standard log for _t.

Parameters
_tMessage to print
_argsMore messages to add

◆ rgbBgSet()

std::string ciof::rgbBgSet ( unsigned int r,
unsigned int g,
unsigned int b )

Set the RGB color for background in the terminal.

Parameters
rRed color
gGreen color
bBlue color
Returns
std::string Color escape sequence for RGB colors

Definition at line 86 of file ciof.cpp.

87 {
88 return "\033[48;2;" + std::to_string(r) + ";"
89 + std::to_string(g) + ";"
90 + std::to_string(b) + "m";
91 }

◆ rgbSet()

std::string ciof::rgbSet ( unsigned int r,
unsigned int g,
unsigned int b )

Set the RGB color in the terminal.

Parameters
rRed color
gGreen color
bBlue color
Returns
std::string Color escape sequence for RGB colors

Definition at line 79 of file ciof.cpp.

80 {
81 return "\033[38;2;" + std::to_string(r) + ";"
82 + std::to_string(g) + ";"
83 + std::to_string(b) + "m";
84 }

◆ showCursor()

void ciof::showCursor ( const bool & show)

Show or hide the cursor from the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().

Definition at line 67 of file ciof.cpp.

68 {
69 if (show) ciof::echo("\033[?25h");
70 else ciof::echo("\033[?25l");
71 }

References echo().

◆ styleReset()

std::string ciof::styleReset ( )

Reset all the styles and colors in the terminal.

Returns
std::string Escape code to ereset colors and styles from terminal

Definition at line 73 of file ciof.cpp.

74 { return "\033[0m"; }

◆ styleSet()

std::string ciof::styleSet ( const OutputStyle & _style)

Set the styles according to the OutputStyle type.

Parameters
_styleSet the style (Bold, Italics, Underline, ...)
Returns
std::string Escape code according to the style

Definition at line 52 of file ciof.cpp.

53 {
54 switch (_style)
55 {
56 case ciof::OutputStyle::Bold: return "\033[1m";
57 case ciof::OutputStyle::Italic: return "\033[3m";
58 case ciof::OutputStyle::Underline: return "\033[4m";
59 case ciof::OutputStyle::Strikethrough: return "\033[9m";
60 default: return "";
61 }
62 }

References Bold, Italic, Strikethrough, and Underline.

Variable Documentation

◆ outputConf

CIOFOutputConfig ciof::outputConf

Set default output configuration.

Definition at line 16 of file ciof.cpp.