osmanip
Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.
options.hpp
Go to the documentation of this file.
1 //====================================================
2 // File data
3 //====================================================
13 //====================================================
14 // Preprocessor settings
15 //====================================================
16 #pragma once
17 #ifndef OSMANIP_UTILITY_OPTIONS_HPP
18 #define OSMANIP_UTILITY_OPTIONS_HPP
19 
20 //====================================================
21 // Headers
22 //====================================================
23 
24 // My headers
30 
31 // STD headers
32 #include <iostream>
33 #include <string>
34 
35 namespace osm {
36 
37  //====================================================
38  // Enum classes
39  //====================================================
40 
41  // CURSOR
49  enum class CURSOR { ON, OFF };
50 
51  // ANSI
59  enum class ANSI { ON, OFF };
60 
61  // UNICODECH
69  enum class UNICODECH { ON, OFF };
70 
71  //====================================================
72  // OPTION
73  //====================================================
81  template <typename T>
82  inline void OPTION(T opt) {
83  if constexpr (std::is_same_v<T, CURSOR>) {
84  if (opt == CURSOR::ON)
85  osm::cout << feat(tcs, "scrs");
86  else if (opt == CURSOR::OFF)
87  osm::cout << feat(tcs, "hcrs");
88  } else if constexpr (std::is_same_v<T, ANSI>) {
89  if (opt == ANSI::ON)
90  enableANSI();
91  else if (opt == ANSI::OFF)
92  disableANSI();
93  } else if constexpr (std::is_same_v<T, UNICODECH>) {
94  if (opt == UNICODECH::ON)
95  enableUNICODE();
96  else if (opt == UNICODECH::OFF)
98  } else
99  std::cerr << feat(col, "red")
100  << "Inserted cursor option "
101  "is not supported!"
102  << feat(rst, "all") << "\n";
103  }
104 } // namespace osm
105 
106 #endif
Definition: canvas.cpp:30
void disableUNICODE()
Function used to disable UNICODE characters (used for Windows only).
Definition: windows.cpp:125
void enableANSI()
Function used to enable ANSI escape sequences on Windows.
Definition: windows.cpp:59
const std::unordered_map< std::string, std::string > rst
It is used to store the reset features commands.
Definition: colsty.cpp:114
CURSOR
It is used to store the OPTION function options for the cursor view. Current options are: ON to enabl...
Definition: options.hpp:49
const std::unordered_map< std::string, std::string > tcs
It is used to store the terminal control sequences.
Definition: cursor.cpp:56
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...
Definition: colsty.cpp:39
std::ostream cout
UNICODECH
It is used to store the OPTION function options for the UNICODE characters enabling....
Definition: options.hpp:69
void enableUNICODE()
Function used to enable UNICODE characters (used for Windows only).
Definition: windows.cpp:109
void OPTION(T opt)
It is used to set a specific option.
Definition: options.hpp:82
ANSI
It is used to store the OPTION function options for the ANSI escape sequences enabling....
Definition: options.hpp:59
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 a...
Definition: common.cpp:41
void disableANSI()
Function used to disable ANSI escape sequences on Windows.
Definition: windows.cpp:90