-
Notifications
You must be signed in to change notification settings - Fork 1
/
XPlatform.c
62 lines (50 loc) · 1.13 KB
/
XPlatform.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
61
62
/*
* File: XPlatform.c
* Author: Tberdy
*
* Created on 30 septembre 2016, 00:09
*/
#include "XPlatform.h"
#ifdef WINDOWS
char xplt_getch() {
return getch();
}
void xplt_clrscr() {
system("cls");
}
void xplt_gotoligcol(int lig, int col) {
COORD Coord;
Coord.X = col;
Coord.Y = lig;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Coord);
}
void xplt_set_color(int text, int foreground) {
HANDLE H = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(H, foreground * 16 + text);
}
#else
char xplt_getch() {
char c = 0;
system("/bin/stty raw");
while (c == 0) {
c = getchar();
}
system("/bin/stty cooked");
return c;
}
void xplt_clrscr() {
system("clear");
}
void xplt_gotoligcol(int lig, int col) {
printf("\033[%d;%dH", lig + 1, col + 1);
}
void xplt_set_color(int text, int foreground) {
char color[4];
if (text >= 0 && text < 100 && foreground >= 0 && foreground < 100) {
sprintf(color, "%d", text);
printf("\033[%sm", color);
sprintf(color, "%d", foreground + 10);
printf("\033[%sm", color);
}
}
#endif