-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.h
77 lines (59 loc) · 1.49 KB
/
display.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
/* Compatibility for DOS. Note that the DOS API forms the basis for some of
these calls, and thus this compatibility section does not define them. */
#ifndef _CLOCK_DISPLAY
#define _CLOCK_DISPLAY
#ifdef _WIN32
#include <windows.h>
void clrscr() {
HANDLE screen;
COORD pos;
DWORD written;
CONSOLE_SCREEN_BUFFER_INFO screen_attr;
unsigned size;
screen = GetStdHandle(STD_OUTPUT_HANDLE);
pos.X = 0;
pos.Y = 0;
GetConsoleScreenBufferInfo(screen, &screen_attr);
size = screen_attr.dwSize.X * screen_attr.dwSize.Y;
FillConsoleOutputCharacter(screen, ' ', size, pos, &written);
SetConsoleCursorPosition(screen, pos);
}
void gotoxy(short x, short y) {
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void sleep(int seconds) {
Sleep(seconds * 1000);
}
void invertColors() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
}
void restoreColors() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
}
/* Else, assume an ANSI-capable terminal. */
#else
/* UNIX and DOS put their API routines in different headers. */
#ifdef unix
#include <unistd.h>
#else
#include <conio.h>
#endif
void clrscr() {
printf("\033[2J");
}
void gotoxy(char x, char y) {
printf("\033[%d;%dH", y, x);
}
void invertColors() {
printf("\033[7m");
}
void restoreColors() {
printf("\033[0m");
}
#endif
#endif