-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.cpp
More file actions
72 lines (54 loc) · 1.16 KB
/
Copy pathinteractive.cpp
File metadata and controls
72 lines (54 loc) · 1.16 KB
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
#include <cstdio>
#include "interactive.h"
#ifdef __linux__
const int sleep_time=50000;
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
typedef struct termios T;
char keyboard_hit(){
T oldt, newt;
int c, oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
c = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(c != EOF){
return c;
}
return '\0';
}
void clear_screen(){
printf("\x1B[2J\x1B[H");
return;
}
void wait_to_next(){
usleep(sleep_time);
}
#elif _WIN32
const int sleep_time=40;
#include<conio.h>
#include<cstring>
#include<windows.h>
void clear_screen(){
COORD CursorPosition;
CursorPosition.X = 0;
CursorPosition.Y = 0;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),CursorPosition);
}
char keyboard_hit(){
if (kbhit()){
char key=getch();
return key;
}
return '\0';
}
void wait_to_next(){
Sleep(sleep_time);
}
#endif