3 #include <sys/select.h>
10 /**************************************************/
12 static struct termios orig_termios;
14 /**************************************************/
16 static void reset_terminal_mode()
18 tcsetattr(0, TCSANOW, &orig_termios);
21 static void set_conio_terminal_mode()
23 struct termios new_termios;
25 /* take two copies - one for now, one for later */
26 tcgetattr(0, &orig_termios);
27 memcpy(&new_termios, &orig_termios, sizeof(new_termios));
29 /* register cleanup handler, and set the new terminal mode */
30 atexit(reset_terminal_mode);
31 cfmakeraw(&new_termios);
32 tcsetattr(0, TCSANOW, &new_termios);
35 static int kbhit(void)
37 struct timeval tv = { 0L, 0L };
40 return select(1, &fds, NULL, NULL, &tv);
43 static int getch(void)
47 if ((r = read(0, &c, 1)) < 0)
53 /**************************************************/
57 set_conio_terminal_mode();
62 if (console_rx_ready_callback())
65 console_rx_callback(getch());