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. */
15 #include "pd_readline.h"
18 /* This implementation of getch() is from here - */
19 /* http://wesley.vidiqatch.org/ */
21 static struct termios old, new;
23 /* Initialize new terminal i/o settings */
24 void initTermios(int echo) {
25 tcgetattr(0, &old); /* grab old terminal i/o settings */
26 new = old; /* make new settings same as old settings */
27 new.c_lflag &= ~ICANON; /* disable buffered i/o */
28 new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
29 tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
33 /* Restore old terminal i/o settings */
34 void resetTermios(void) {
35 tcsetattr(0, TCSANOW, &old);
39 /* Read 1 character - echo defines echo mode */
40 char getch_(int echo) {
49 /* Read 1 character without echo */
55 /* Read 1 character with echo */
68 case (27): puts("1"); /* escape() ; */
69 case (33): puts("2"); /* dosomething(); */
70 case (42): puts("3"); /* something(); */
71 default: puts("4"); /* stuff(); */