forked from sruthi2498/MyShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrow.c
62 lines (53 loc) · 1.01 KB
/
arrow.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
#include "all_include.h"
int pressed_arrow(){
int c = 0;
static struct termios oldTermios, newTermios;
tcgetattr(STDIN_FILENO, &oldTermios);
newTermios = oldTermios;
cfmakeraw(&newTermios);
tcsetattr(STDIN_FILENO, TCSANOW, &newTermios);
c = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldTermios);
if(c==27){
tcsetattr(STDIN_FILENO, TCSANOW, &newTermios);
c = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldTermios);
if(c==91){
tcsetattr(STDIN_FILENO, TCSANOW, &newTermios);
c = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldTermios);
if(c==65){
printf("up");
return 1;
}
else if(c==66){
printf("down");
return 2;
}
else{
ungetc(c, stdin);
return 0;
}
}
else{
ungetc(c, stdin);
return 0;
}
}
else if(c==3 || c==26){
ungetc(c, stdin);
return -1;
}
else{
ungetc(c, stdin);
return 0;
}
return 0;
}
// int main(){
// int a;
// a=pressed_arrow();
// while(a!=-1){
// a=pressed_arrow();
// }
// }