CIOF v1.2.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# include <VersionHelpers.h>
12#endif
13
14namespace ciof
15{
17
18 void print()
19 { std::cout << std::endl; }
20
21 void input()
22 {
23 std::string empty;
24
25 ciof::input(&empty);
26 }
27
28 std::string getCursorPos(int _row, int _col)
29 { return std::string("\033[" + std::to_string(_row) + ";" + std::to_string(_col) + "H"); }
30
31 void cursorPos(int _row, int _col)
32 { std::cout << getCursorPos(_row, _col) << std::flush; }
33
34 void initANSI()
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 }
51
52 std::string styleSet(const OutputStyle &_style)
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 }
63
64 void clear()
65 { ciof::echo("\033[2J\033[H"); }
66
67 void showCursor(const bool &show)
68 {
69 if (show) ciof::echo("\033[?25h");
70 else ciof::echo("\033[?25l");
71 }
72
73 std::string styleReset()
74 { return "\033[0m"; }
75
76 std::string colorSet(int _color)
77 { return "\033[" + std::to_string(_color) + "m"; }
78
79 std::string rgbSet(unsigned int r, unsigned int g, unsigned int b)
80 {
81 return "\033[38;2;" + std::to_string(r) + ";"
82 + std::to_string(g) + ";"
83 + std::to_string(b) + "m";
84 }
85
86 std::string rgbBgSet(unsigned int r, unsigned int g, unsigned int b)
87 {
88 return "\033[48;2;" + std::to_string(r) + ";"
89 + std::to_string(g) + ";"
90 + std::to_string(b) + "m";
91 }
92}
Definition ciof.hpp:19
void initANSI()
Initialize ANSI text option in Windows 10 or later NOTE: ONLY WORKS IN WINDOWS 10 OR LATER.
Definition ciof.cpp:34
std::string rgbBgSet(unsigned int r, unsigned int g, unsigned int b)
Set the RGB color for background in the terminal.
Definition ciof.cpp:86
void showCursor(const bool &show)
Show or hide the cursor from the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().
Definition ciof.cpp:67
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:31
std::string getCursorPos(int _row, int _col)
Get the set cursor position using _row and _col.
Definition ciof.cpp:28
std::string styleReset()
Reset all the styles and colors in the terminal.
Definition ciof.cpp:73
std::string rgbSet(unsigned int r, unsigned int g, unsigned int b)
Set the RGB color in the terminal.
Definition ciof.cpp:79
OutputStyle
Set output style: Bold Italic Underline Strikethrough.
Definition ciof.hpp:59
void input()
Empty input() function; Do not save any input to a variable, just leave it as a blank input.
Definition ciof.cpp:21
CIOFOutputConfig outputConf
Set default output configuration.
Definition ciof.cpp:16
void print()
Print a new line.
Definition ciof.cpp:18
std::string styleSet(const OutputStyle &_style)
Set the styles according to the OutputStyle type.
Definition ciof.cpp:52
void clear()
Clear the contents of the terminal NOTE: In Windows; enable ANSI by doing ciof::initANSI().
Definition ciof.cpp:64
void echo(T _t)
Echo to the standard output for _t.
std::string colorSet(int _color)
Set the colors from the default color palette from the terminal.
Definition ciof.cpp:76
Set output configuration for ciof::impl::__out() function and its wrappers.
Definition ciof.hpp:24