annotate linuxconio.h @ 8:c60e4315cb7e

Automated Vimcurial commmit
author VilyaemKenyaz
date Tue, 12 Sep 2023 06:46:45 -0400
parents 1bb981516d87
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
1 #ifndef CONIO_H
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
2 #define CONIO_H
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
3
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
4 #include <termios.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
5 #include <unistd.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
6 #include <stdio.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
7 #include <fcntl.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
8 #include <stdlib.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
9 #include <string.h>
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
10
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
11 #define cprintf printf
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
12 #define cscanf scanf
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
13 #define cgets gets
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
14
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
15 #define CLEAR "\x1b[2J"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
16 #define SET11 "\x1b[1;1f"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
17 #define CURSOR_UP "\x1b[1A"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
18 #define ERASE_LINE "\x1b[2K"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
19 #define BLINK_SLOW "\x1b[5m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
20 #define BLINK_RAPID "\x1b[6m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
21 #define CC_CLEAR "\x1b[0m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
22
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
23 #define BLACK "\x1b[30m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
24 #define RED "\x1b[31m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
25 #define GREEN "\x1b[32m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
26 #define YELLOW "\x1b[33m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
27 #define BLUE "\x1b[34m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
28 #define MAGENTA "\x1b[35m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
29 #define CYAN "\x1b[36m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
30 #define WHITE "\x1b[37m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
31
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
32 #define IBLACK "\x1b[30;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
33 #define IRED "\x1b[31;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
34 #define IGREEN "\x1b[32;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
35 #define IYELLOW "\x1b[33;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
36 #define IBLUE "\x1b[34;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
37 #define IMAGENTA "\x1b[35;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
38 #define ICYAN "\x1b[36;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
39 #define IWHITE "\x1b[37;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
40
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
41 #define BGC_BLACK "\x1b[40m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
42 #define BGC_RED "\x1b[41m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
43 #define BGC_GREEN "\x1b[42m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
44 #define BGC_YELLOW "\x1b[43m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
45 #define BGC_BLUE "\x1b[44m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
46 #define BGC_MAGENTA "\x1b[45m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
47 #define BGC_CYAN "\x1b[46m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
48 #define BGC_WHITE "\x1b[47m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
49
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
50 #define BGC_IBLACK "\x1b[40;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
51 #define BGC_IRED "\x1b[41;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
52 #define BGC_IGREEN "\x1b[42;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
53 #define BGC_IYELLOW "\x1b[43;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
54 #define BGC_IBLUE "\x1b[44;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
55 #define BGC_IMAGENTA "\x1b[45;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
56 #define BGC_ICYAN "\x1b[46;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
57 #define BGC_IWHITE "\x1b[47;1m"
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
58
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
59 static struct termios oldterm, newterm;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
60
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
61 void initTermios(int echo)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
62 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
63 tcgetattr(0, &oldterm);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
64 newterm = oldterm;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
65 newterm.c_lflag &= ~ICANON;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
66 newterm.c_lflag &= echo ? ECHO : ~ECHO;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
67 tcsetattr(0, TCSANOW, &newterm);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
68 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
69 void resetTermios(void)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
70 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
71 tcsetattr(0, TCSANOW, &oldterm);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
72 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
73
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
74 int getch_(int echo)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
75 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
76 int ch;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
77 initTermios(echo);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
78 ch = getchar();
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
79 resetTermios();
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
80 return ch;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
81 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
82
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
83 void cagxy(unsigned int x, unsigned int y)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
84 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
85 printf("%s\x1b[%d;%df", CLEAR, y, x);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
86 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
87
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
88 void clrscr()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
89 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
90 printf("%s%s",CLEAR, SET11);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
91 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
92
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
93 int getch(void)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
94 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
95 return getch_(0);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
96 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
97
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
98 int getche(void)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
99 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
100 return getch_(1);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
101 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
102
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
103 void gotox(unsigned int x)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
104 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
105 printf("\x1b[%dG", x);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
106 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
107
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
108 void gotoxy(unsigned int x, unsigned int y)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
109 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
110 printf("\x1b[%d;%df", y, x);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
111 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
112
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
113 void nocursor()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
114 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
115 printf("\x1b[?25l");
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
116 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
117
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
118 void reset_video()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
119 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
120 printf("\x1b[0m");
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
121 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
122
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
123 void showcursor()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
124 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
125 printf("\x1b[?25h");
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
126 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
127
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
128 void textcolor(char *color)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
129 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
130 printf("%s",color);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
131 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
132
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
133 void textbackground(char color[11])
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
134 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
135 char col[11];
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
136 strcpy(col,color);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
137 col[2]='4';
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
138 printf("%s",col);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
139 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
140
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
141 void delline()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
142 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
143 printf("%s%s", ERASE_LINE, CURSOR_UP);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
144 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
145
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
146 void clreol()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
147 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
148 printf("%s",CLEAR);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
149 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
150 int putch(const char c)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
151 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
152 printf("%c",c);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
153 return (int)c;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
154 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
155
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
156 int cputs(const char*str)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
157 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
158 printf(str);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
159 return 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
160 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
161
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
162
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
163 int wherexy(int *x, int *y)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
164 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
165 printf("\033[6n");
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
166 if(getch() != '\x1B') return 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
167 if(getch() != '\x5B') return 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
168 int in;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
169 int ly = 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
170 while((in = getch()) != ';')
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
171 ly = ly * 10 + in - '0';
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
172 int lx = 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
173 while((in = getch()) != 'R')
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
174 lx = lx * 10 + in - '0';
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
175 *x = lx;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
176 *y = ly;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
177 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
178 int wherex()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
179 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
180 int x=0,y=0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
181 wherexy(&x, &y);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
182 return x;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
183 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
184
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
185 int wherey()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
186 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
187 int x=0,y=0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
188 wherexy(&x, &y);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
189 return y;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
190 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
191
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
192 int kbhit()
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
193 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
194 struct termios oldt, newt;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
195 int ch;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
196 int oldf;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
197
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
198 tcgetattr(STDIN_FILENO, &oldt);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
199 newt = oldt;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
200 newt.c_lflag &= ~(ICANON | ECHO);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
201 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
202 oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
203 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
204
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
205 ch = getchar();
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
206
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
207 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
208 fcntl(STDIN_FILENO, F_SETFL, oldf);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
209
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
210 if(ch != EOF)
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
211 {
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
212 ungetc(ch, stdin);
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
213 return 1;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
214 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
215 return 0;
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
216 }
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
217 #endif
1bb981516d87 Automated Vimcurial commmit
VilyaemKenyaz
parents:
diff changeset
218