osmanip
Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.
|
Classes | |
class | Canvas |
Instances of this class are used to draw in a limited 2D space. All the functions that modify the canvas do it internally; to make the changes effective in the console, you must use the refresh method. More... | |
class | Plot2DCanvas |
This class is used to plot mathematical functions R -> R. In addition to all the properties of a basic Canvas, this one also has an offset and a scale for the plot. The offset is the first value in x and y to be represented in the canvas and the scale is the difference in x or y that each character represents relative to the previous one. For example: a canvas of size = (15, 10) with offset = (3,2) and scale = (7, 5) will represent the functions you draw from x=3 to x=3+15*7=108 and from y=2 to y=2+10*5=52. More... | |
class | Decorator |
Class used to decorate an output stream. Each setting is set permanently on the chosen output stream until the destructor is met or one of the reset functions is called. More... | |
struct | indices |
Type to generate indices for parameter packs. More... | |
struct | gen_indices |
Type to generate indices for parameter packs. More... | |
struct | gen_indices< 0, Is... > |
Type to generate indices for parameter packs. More... | |
class | make_MultiProgressBar |
Template class used to create multi progress bars. More... | |
struct | type_identity |
Struct used to to typedef the functor. More... | |
struct | updater |
Functor used to call the ProgressBar class update method. More... | |
class | ProgressBar |
Template class used to create customized progress bars. More... | |
class | OutputRedirector |
This class is used to redirected output to a file. More... | |
class | Stringbuf |
This class inherits std::stringbuf and adds additional functionality and thread safety. More... | |
class | Ostreambuf |
This class inherits Stringbuf and adds the ability to send output to a specific std::ostream buffer as well as redirect output to osm::redirout. More... | |
Typedefs | |
using | string_pair_map = std::unordered_map< std::string, std::pair< std::string, std::string > > |
using | string_set_map = std::unordered_map< std::string, std::unordered_set< std::string > > |
using | steady_clock = std::chrono::steady_clock |
using | duration = std::chrono::duration< float, steady_clock::period > |
Enumerations | |
enum | FrameStyle { EMPTY = 0 , ASCII = 1 , BOX = 2 } |
Enum class used to define the frame style. More... | |
enum class | ANSI_SEARCH { first , generic } |
enum class | CURSOR { ON , OFF } |
It is used to store the OPTION function options for the cursor view. Current options are: ON to enable cursor view and OFF to disable it. More... | |
enum class | ANSI { ON , OFF } |
It is used to store the OPTION function options for the ANSI escape sequences enabling. Current options are: ON to enable and OFF to disable. More... | |
enum class | UNICODECH { ON , OFF } |
It is used to store the OPTION function options for the UNICODE characters enabling. Current options are: ON to enable and OFF to disable. More... | |
Functions | |
const std::string | RGB (int32_t r, int32_t g, int32_t b) |
It takes three integers as arguments which are the corresponding rgb triplets of a color (see here for the full list of available colors http://www.aksiom.net/rgb.html). It can be used to output a wider variety of colors with respect to the standard available from the col map. More... | |
const std::string & | feat (const std::unordered_map< std::string, std::string > &generic_map, const std::string &feat_string) |
It takes an std::map object as the first argument and an std::string object (map key) as the second argument and returns the interested color / style feature by returning the map value from the corresponding key. More... | |
const std::string | feat (const string_pair_map &generic_map, const std::string &feat_string, int32_t feat_int) |
This overload, with respect to the standard function definition, takes an std::map object as the first argument, but with an std::pair as second type and additionally takes an extra integer argument to correctly set the parameter of the crs map. More... | |
const std::string | go_to (int32_t x, int32_t y) |
It takes two integers as arguments which are the x and y position of the cursor in the screen and returns the interested position you want to reach. More... | |
std::vector< std::string > | split_string (const std::string &input, const std::string ®ex) |
Function used to split a string based on a certain reges. More... | |
std::string | getCommandOut (const char *command) |
Function used to get the output of a shell command. More... | |
std::string | trim_string (const std::string &str) |
Removes all leading and trailing spaces from a string. More... | |
size_t | find_first_alpha (std::string_view str, size_t pos) |
Finds the index of the first alphabetic character in the str, starting from the given position. More... | |
std::string | get_formatted_from_ansi (const std::string &str, int32_t *last_pos, int32_t *last_size) |
Formats a string according to the ANSI (Control Sequence Introducer) escape sequences present within the string. Can be used in a loop with appending data by using optional arguments. More... | |
std::string | get_ansi_csi_string (const std::string &str, size_t esc_pos) |
int32_t | get_ansi_csi_number (const std::string &csi) |
char | get_ansi_csi_code (const std::string &csi) |
void | enableANSI () |
Function used to enable ANSI escape sequences on Windows. More... | |
void | disableANSI () |
Function used to disable ANSI escape sequences on Windows. More... | |
void | enableUNICODE () |
Function used to enable UNICODE characters (used for Windows only). More... | |
void | disableUNICODE () |
Function used to disable UNICODE characters (used for Windows only). More... | |
template<typename T > | |
std::ostream & | operator<< (Decorator my_shell, const T &elem) |
Operator overload to output a modified ostream object which properties are set thanks to the Decorator class. More... | |
template<class... Indicators> | |
make_MultiProgressBar< typename std::remove_reference< Indicators >::type... > | MultiProgressBar (Indicators &&...inds) |
Helper function used for deduction guides. More... | |
template<typename bar_type > | |
std::ostream & | operator<< (std::ostream &os, const ProgressBar< bar_type > &pb) |
Operator << used to print the progress bar properties. More... | |
template<typename T_err = std::runtime_error> | |
T_err | except_error_func (const std::string &beg="", std::string var=nullptr, const std::string &end="") |
Function used to throw customized stdexception error. This function is extremely specific to my purposes and you can find examples usages in other my projects lik "osmanip" or "SAFD-algorithm". More... | |
template<typename T > | |
bool | is_escape (const T &str, const ANSI_SEARCH &flag) |
This method is used to check if an input variable is an ANSI escape sequency or not. More... | |
template<typename T > | |
T | roundoff (T value, unsigned char prec) |
Function to round a floating point to n-th decimal place after comma. More... | |
template<typename T > | |
bool | isFloatingPoint (const T &) |
Function to check if an expression (not a type) is a floating point or not. I know this function is almost useless, but it has been created for lazy purposes and since it is used in other projects it cannot be eliminated now in order to not break backward compatibility. More... | |
template<typename T > | |
T | one (const T &iterating_var) |
Function to find the incremented unit of a loop. Not easy to understand its purpose without context, but it is used to get the loop incremented unit in case of loops with floating-point indexes. See example usage in progress bars "update" method. More... | |
template<typename T > | |
void | OPTION (T opt) |
It is used to set a specific option. More... | |
std::string | trim_string (std::string &str) |
void | handle_csi (const std::string &csi_str, std::string &dst_str, int32_t *dst_crsr_pos) |
Variables | |
const std::unordered_map< std::string, std::string > | col |
It is used to store the colors. Note: "bg" is the prefix of the background color features and "bd" is the one of the bold color features. More... | |
const std::unordered_map< std::string, std::string > | sty |
It is used to store the styles. More... | |
const std::unordered_map< std::string, std::string > | rst |
It is used to store the reset features commands. More... | |
const string_pair_map | crs |
It is used to store the cursor commands. More... | |
const std::unordered_map< std::string, std::string > | tcs |
It is used to store the terminal control sequences. More... | |
const string_pair_map | tcsc |
It is used to store the terminal control sequences for clear line / screen. More... | |
Ostreambuf | cout_buf {&std::cout} |
OutputRedirector | redirout {} |
Link to osm::cout. More... | |
std::string | old_chcp |
template<typename T > | |
const T | null_str = "" |
template<typename T > | |
const T | empty_space = " " |
std::ostream | cout |
using osm::duration = typedef std::chrono::duration<float, steady_clock::period> |
using osm::steady_clock = typedef std::chrono::steady_clock |
using osm::string_pair_map = typedef std::unordered_map<std::string, std::pair<std::string, std::string> > |
using osm::string_set_map = typedef std::unordered_map<std::string, std::unordered_set<std::string> > |
|
strong |
|
strong |
|
strong |
enum osm::FrameStyle |
|
strong |
void osm::disableANSI | ( | ) |
Function used to disable ANSI escape sequences on Windows.
void osm::disableUNICODE | ( | ) |
Function used to disable UNICODE characters (used for Windows only).
void osm::enableANSI | ( | ) |
Function used to enable ANSI escape sequences on Windows.
void osm::enableUNICODE | ( | ) |
Function used to enable UNICODE characters (used for Windows only).
|
inline |
Function used to throw customized stdexception error. This function is extremely specific to my purposes and you can find examples usages in other my projects lik "osmanip" or "SAFD-algorithm".
T_err | The type of the exception error. |
beg | The first part of the error message. |
var | The variable to be inserted in the error message. |
end | The last part of the error message. |
const std::string & osm::feat | ( | const std::unordered_map< std::string, std::string > & | generic_map, |
const std::string & | feat_string | ||
) |
It takes an std::map object as the first argument and an std::string object (map key) as the second argument and returns the interested color / style feature by returning the map value from the corresponding key.
generic_map | The feature map. |
feat_string | The feature name. |
const std::string osm::feat | ( | const string_pair_map & | generic_map, |
const std::string & | feat_string, | ||
int32_t | feat_int | ||
) |
This overload, with respect to the standard function definition, takes an std::map object as the first argument, but with an std::pair as second type and additionally takes an extra integer argument to correctly set the parameter of the crs map.
generic_map | The feature map. |
feat_string | The feature name. |
feat_int | Extra integer argument to correctly set the parameter of the crs map. |
size_t osm::find_first_alpha | ( | std::string_view | str, |
size_t | pos | ||
) |
Finds the index of the first alphabetic character in the str, starting from the given position.
str | the string be searched. |
pos | the starting position. |
char osm::get_ansi_csi_code | ( | const std::string & | csi | ) |
int32_t osm::get_ansi_csi_number | ( | const std::string & | csi | ) |
std::string osm::get_ansi_csi_string | ( | const std::string & | str, |
size_t | esc_pos | ||
) |
std::string osm::get_formatted_from_ansi | ( | const std::string & | str, |
int32_t * | last_pos, | ||
int32_t * | last_size | ||
) |
Formats a string according to the ANSI (Control Sequence Introducer) escape sequences present within the string. Can be used in a loop with appending data by using optional arguments.
str | the string to be formatted. |
last_pos | [Optional] the final position (index) of the last string to be formatted. |
last_size | [Optional] the size of the last string to be formatted. |
std::string osm::getCommandOut | ( | const char * | command | ) |
Function used to get the output of a shell command.
command | The command which output is required. |
const std::string osm::go_to | ( | int32_t | x, |
int32_t | y | ||
) |
It takes two integers as arguments which are the x and y position of the cursor in the screen and returns the interested position you want to reach.
x | The x position of the cursor in the screen. |
y | The y position of the cursor in the screen |
void osm::handle_csi | ( | const std::string & | csi_str, |
std::string & | dst_str, | ||
int32_t * | dst_crsr_pos | ||
) |
bool osm::is_escape | ( | const T & | str, |
const ANSI_SEARCH & | flag | ||
) |
This method is used to check if an input variable is an ANSI escape sequency or not.
T | Template type of the input variable. |
str | The input variable. |
flag | A flag which let to return different things with respect to its value. If flag = ANSI_SEARCH::first the ANSI is searched as the first substring of the str argument, otherwise, if flag = ANSI_SEARCH::generic the ANSI is searched as a substring inside the str argument. |
|
inline |
Function to check if an expression (not a type) is a floating point or not. I know this function is almost useless, but it has been created for lazy purposes and since it is used in other projects it cannot be eliminated now in order to not break backward compatibility.
T | The type of the expression. |
make_MultiProgressBar<typename std::remove_reference<Indicators>::type...> osm::MultiProgressBar | ( | Indicators &&... | inds | ) |
Helper function used for deduction guides.
Indicators | The parameter pack of the various progress bar types. |
inds | The progress bars. |
|
inline |
Function to find the incremented unit of a loop. Not easy to understand its purpose without context, but it is used to get the loop incremented unit in case of loops with floating-point indexes. See example usage in progress bars "update" method.
T | The type of the iterating variable of the loop. |
iterating_var | The iterating variable of the loop. |
std::ostream& osm::operator<< | ( | Decorator | my_shell, |
const T & | elem | ||
) |
Operator overload to output a modified ostream object which properties are set thanks to the Decorator class.
T | The template parameter of the object sent into the output stream. |
my_shell | The Decorator object. |
elem | The element sent into the output stream. |
std::ostream& osm::operator<< | ( | std::ostream & | os, |
const ProgressBar< bar_type > & | pb | ||
) |
Operator << used to print the progress bar properties.
bar_type | It is the type of the progress bar. |
os | It is the output stream used to print the progress bar. |
pb | It is the progress bar object. |
|
inline |
It is used to set a specific option.
T | The type of the given option. |
opt | The option to be set. |
const std::string osm::RGB | ( | int32_t | r, |
int32_t | g, | ||
int32_t | b | ||
) |
It takes three integers as arguments which are the corresponding rgb triplets of a color (see here for the full list of available colors http://www.aksiom.net/rgb.html). It can be used to output a wider variety of colors with respect to the standard available from the col map.
r | The r singlet of the tripled. |
g | The g singlet of the tripled. |
b | The b singlet of the tripled. |
|
inline |
Function to round a floating point to n-th decimal place after comma.
T | The Type of the variable to be rounded. |
value | The variable to be rounded |
prec | Precision of the rounding. |
std::vector< std::string > osm::split_string | ( | const std::string & | input, |
const std::string & | regex | ||
) |
Function used to split a string based on a certain reges.
input | The input string. |
regex | The regex. |
std::string osm::trim_string | ( | const std::string & | str | ) |
Removes all leading and trailing spaces from a string.
str | the string to be trimmed. |
std::string osm::trim_string | ( | std::string & | str | ) |
const std::unordered_map< std::string, std::string > osm::col |
It is used to store the colors. Note: "bg" is the prefix of the background color features and "bd" is the one of the bold color features.
|
extern |
std::ostream cout & osm::cout_buf {&std::cout} |
const string_pair_map osm::crs |
It is used to store the cursor commands.
|
inline |
|
inline |
std::string osm::old_chcp |
OutputRedirector osm::redirout {} |
Link to osm::cout.
Linked to standard output.
const std::unordered_map< std::string, std::string > osm::rst |
It is used to store the reset features commands.
const std::unordered_map< std::string, std::string > osm::sty |
It is used to store the styles.
const std::unordered_map< std::string, std::string > osm::tcs |
It is used to store the terminal control sequences.
const string_pair_map osm::tcsc |
It is used to store the terminal control sequences for clear line / screen.