CIOF v1.0.0-build
Char Input Output Format - A simple Input and Output utility library
Loading...
Searching...
No Matches
ciof.cpp
Go to the documentation of this file.
1#include <iostream>
2
4
5#ifndef __CIOF_OK
6# error "CIOF Is not OK, make sure to not have any errors at compile time"
7#endif // NOT : __CIOF_OK
8
9#ifdef CIOF_OS_WIN32
10# include <windows.h>
11#endif
12
13namespace ciof
14{
16
17 void print()
18 { std::cout << std::endl; }
19
20 std::string getCursorPos(int _row, int _col)
21 { return std::string("\033[" + std::to_string(_row) + ";" + std::to_string(_col) + "H"); }
22
23 void cursorPos(int _row, int _col)
24 { std::cout << getCursorPos(_row, _col) << std::flush; }
25
26 void initANSI()
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 }
43
44 std::string styleSet(const OutputStyle &_style)
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 }
55
56 std::string styleReset()
57 { return "\033[0m"; }
58
59 std::string colorSet(int _color)
60 { return "\033[" + std::to_string(_color) + "m"; }
61
62 std::string rgbSet(unsigned int r, unsigned int g, unsigned int b)
63 {
64 return "\033[38;2;" + std::to_string(r) + ";"
65 + std::to_string(g) + ";"
66 + std::to_string(b) + "m";
67 }
68}
Definition ciof.hpp:12
void initANSI()
Initialize ANSI text option in Windows 10 or later NOTE: ONLY WORKS IN WINDOWS 10 OR LATER.
Definition ciof.cpp:26
void cursorPos(int _row, int _col)
Get the set cursor position using _row and _col Essentially calls the getCursorPos() function and the...
Definition ciof.cpp:23
std::string getCursorPos(int _row, int _col)
Get the set cursor position using _row and _col.
Definition ciof.cpp:20
std::string styleReset()
Reset all the styles and colors in the terminal.
Definition ciof.cpp:56
std::string rgbSet(unsigned int r, unsigned int g, unsigned int b)
Set the RGB color in the terminal.
Definition ciof.cpp:62
OutputStyle
Set output style: Bold Italic Underline Strikethrough.
Definition ciof.hpp:52
CIOFOutputConfig outputConf
Set default output configuration.
Definition ciof.cpp:15
void print()
Print a new line.
Definition ciof.cpp:17
std::string styleSet(const OutputStyle &_style)
Set the styles according to the OutputStyle type.
Definition ciof.cpp:44
std::string colorSet(int _color)
Set the colors from the default color palette from the terminal.
Definition ciof.cpp:59
Set output configuration for ciof::impl::__out() function and its wrappers.
Definition ciof.hpp:17