-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.c
60 lines (48 loc) · 874 Bytes
/
utility.c
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
// utility.c
#include "functions.h"
void colRed() {
printf("\033[1;31m");
}
void colGreen() {
printf("\033[1;32m");
}
void colYellow() {
printf("\033[1;33m");
}
void colBlue() {
printf("\033[1;34m");
}
void colMagenta() {
printf("\033[1;35m");
}
void colCyan() {
printf("\033[1;36m");
}
void colReset() {
printf("\033[0m");
}
void clearLine() {
printf("\33[2K\r");
}
void printNewline() {
clearLine();
colGreen();
printf("?: ");
colReset();
};
void printError(char *msg) {
colRed();
printf("ERROR: %s\n", msg);
colReset();
}
int getChar() {
struct termios oldt, newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}