5 /* Handle keystrokes for pd_readline. */
6 /* This code is released to the public domain. */
7 /* "Share and enjoy...." ;) */
8 /* See the UNLICENSE file for details. */
17 /* This implementation of getch() is from here - */
18 /* http://wesley.vidiqatch.org/ */
20 static struct termios old, new;
22 /* Initialize new terminal i/o settings */
23 void initTermios(int echo) {
24 tcgetattr(0, &old); /* grab old terminal i/o settings */
25 new = old; /* make new settings same as old settings */
26 new.c_lflag &= ~ICANON; /* disable buffered i/o */
27 new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
28 tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
32 /* Restore old terminal i/o settings */
33 void resetTermios(void) {
34 tcsetattr(0, TCSANOW, &old);
38 /* Read 1 character - echo defines echo mode */
39 char getch_(int echo) {
48 /* Read 1 character without echo */
54 /* Read 1 character with echo */
68 case (33): dosomething();
69 case (42): something();