CIOF v1.0.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

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.
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 rgbSet (unsigned int r, unsigned int g, unsigned int b)
 Set the RGB color in the terminal.
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 51 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 37 of file ciof.hpp.

38 {
39 Out, // std::cout
40 Err, // std::cerr
41 Log, // std::clog
42 };

Function Documentation

◆ 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 59 of file ciof.cpp.

60 { 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 23 of file ciof.cpp.

24 { 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:20

References getCursorPos().

◆ echo() [1/2]

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

Echo to the standard output for _t

Parameters
_tMessage to print

◆ 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 20 of file ciof.cpp.

21 { 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 26 of file ciof.cpp.

27 {
28# ifdef CIOF_OS_WIN32
29 // NOTE:
30 // This must ONLY be used in Windows 10 or newer
31 if (!IsWindows10OrGreater()) return;
32
33 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
34 DWORD dwMode = 0;
35
36 GetConsoleMode(hOut, &dwMode);
37
38 dwMode |= ENABLE_VIRTUAL_PROCESSING
39
40 SetConsoleMode(hOut, dwMode)
41# endif
42 }

◆ input() [1/2]

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() [2/2]

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 17 of file ciof.cpp.

18 { 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

◆ 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 62 of file ciof.cpp.

63 {
64 return "\033[38;2;" + std::to_string(r) + ";"
65 + std::to_string(g) + ";"
66 + std::to_string(b) + "m";
67 }

◆ 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 56 of file ciof.cpp.

57 { 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 44 of file ciof.cpp.

45 {
46 switch (_style)
47 {
48 case ciof::OutputStyle::Bold: return "\033[1m";
49 case ciof::OutputStyle::Italic: return "\033[3m";
50 case ciof::OutputStyle::Underline: return "\033[4m";
51 case ciof::OutputStyle::Strikethrough: return "\033[9m";
52 default: return "";
53 }
54 }

References Bold, Italic, Strikethrough, and Underline.

Variable Documentation

◆ outputConf

CIOFOutputConfig ciof::outputConf

Set default output configuration.

Definition at line 15 of file ciof.cpp.