-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUserInterface.h
180 lines (155 loc) · 4.75 KB
/
UserInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#pragma clang diagnostic push
#pragma ide diagnostic ignored "modernize-use-nodiscard"
#ifndef CTDL_GK_USERINTERFACE_CPP
#define CTDL_GK_USERINTERFACE_CPP
#include <windows.h>
#include <vector>
#include <string>
enum [[maybe_unused]] g_Color {
DEFAULT_COLOR = 7,
BLACK = 0,
BLUE = 1,
GREEN = 2,
CYAN = 3,
RED = 4,
PURPLE = 5,
YELLOW = 6,
WHITE = 7,
GRAY = 8,
LIGHT_BLUE = 9,
LIGHT_GREEN = 10,
LIGHT_CYAN = 11,
LIGHT_RED = 12,
LIGHT_PURPLE = 13,
LIGHT_YELLOW = 14,
BRIGHT_WHITE = 15
};
/**
* @class UserInterface
* @brief Class for UserInterface
* @details This class contains functions for UserInterface
* @note This class is only for Windows
*/
class UserInterface {
private:
HANDLE _hConsoleHandle;
HANDLE _hInputHandle;
static bool isElevated();
COORD _getScreenSize() const;
COORD _getCursorPosition() const;
void _setCursorPosition(int x, int y) const;
void _moveCursor(int dx = 0, int dy = 0) const;
void _hideInput() const;
void _showInput() const;
public:
char cBorder = '#';
UserInterface();
~UserInterface();
/**
* @brief Clear console screen
*
* @return void
*/
void clearScreen() const;
/**
* @brief Set color for subsequent output
*
* @param color: Color to set
* @return void
*/
void setColor(int color = DEFAULT_COLOR) const;
/**
* @brief Print text to console
*
* @param text Text to print
* @param color Color of text
* @param newLine Print new line after text
* @return void
*/
void print(const std::string& text, int color = DEFAULT_COLOR, bool newLine = true) const;
/**
* @brief Print multiple lines of text to console
*
* @param items Items to print (vector of strings)
* @param color Color of text
* @param newLine Print new line after text
* @param separator Separator character
* @return void
*/
void
print(const std::vector<std::string>& items, int color = DEFAULT_COLOR, bool newLine = true, char separator = '\n'
) const;
/**
* @brief Print a table to console
*
* @param items Items to print (vector of strings)
* @param color Color of text
* @param newLine Print new line after text
* @param separator Separator character
* @param center Center text
* @return void
*/
void printTable(const std::vector<std::vector<std::string>>& items, int color = DEFAULT_COLOR, bool newLine = true,
char separator = ' ', bool center = false
) const;
/**
* @brief Print text to console, centered
*
* @param text Text to print
* @param color Color of text
* @param newLine Print new line after text
* @param padding Padding character
* @param cap Cap character
* @param capColor Color of cap and padding character
* @return void
*/
void printCentered(const std::string& text, int color = DEFAULT_COLOR, bool newLine = true, char padding = ' ',
char cap = ' ', int capColor = DEFAULT_COLOR
) const;
/**
* @brief Print full line of character to console
*
* @param c Character to print
* @param color Color of character
* @param newLine Print new line after text
* @return void
*/
void printLineBreak(char c = ' ', int color = DEFAULT_COLOR, bool newLine = true) const;
/**
* @brief Print title to console (text with border and centered)
*
* @param text Text to print
* @param textColor Text color
* @param borderColor Border color
* @param cap Whether to cap the title
* @return void
*/
void printTitle(const std::string& text, int textColor = DEFAULT_COLOR, int borderColor = DEFAULT_COLOR,
bool cap = false
) const;
/**
* @brief This function is deprecated, use print() instead
*
* @description Print multiple lines of text to console
*
* @param items Items to print (vector of strings)
* @param color Color of the items
* @return void
*/
[[deprecated("This function is deprecated, use print() instead")]]
void printMultiLine(const std::vector<std::string>& items, int color = DEFAULT_COLOR) const;
/**
* @brief Wait for user input
*
* @param message Message to print
* @param color Color of message
* @param hideInput Hide input (for password)
* @param hideChar Character to replace input with (if hideInput is true)
* @return User input
*/
std::string input(const std::string& message = "", int color = DEFAULT_COLOR, bool hideInput = false,
char hideChar = '*'
) const;
};
#endif //CTDL_GK_USERINTERFACE_CPP
#pragma clang diagnostic pop