X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=keyhandler.c;h=f4ca5baa146f729885ca2d639f37cb52bde323d6;hb=d56fdb0ce92c92e27ef45a8315ff26c272a1f23d;hp=80ad5e5461f310dabafdc539c1d0a517fa638533;hpb=3345932d0ab453d9ca85814fde1fe618bb36570f;p=pd_readline diff --git a/keyhandler.c b/keyhandler.c index 80ad5e5..f4ca5ba 100644 --- a/keyhandler.c +++ b/keyhandler.c @@ -21,7 +21,8 @@ static struct termios old, new; /* Initialize new terminal i/o settings */ -void initTermios(int echo) { +void initTermios(int echo) +{ tcgetattr(0, &old); /* grab old terminal i/o settings */ new = old; /* make new settings same as old settings */ new.c_lflag &= ~ICANON; /* disable buffered i/o */ @@ -31,7 +32,8 @@ void initTermios(int echo) { /* Restore old terminal i/o settings */ -void resetTermios(void) { +void resetTermios(void) +{ tcsetattr(0, TCSANOW, &old); } @@ -59,19 +61,33 @@ char getche(void) { -void keyhandler(void) +/* Arrow keys are esc [ A to esc [ D */ +/* Alt keys are just esc then key (e.g. Alt-g is esc g ). */ +/* Ctrl (then letter) keys are just Dec 1 to Dec 26 */ + +void keyhandler(buf b, hist h) { - int i = getch(); + + int a = getch(); - switch(i) + int t = type(a); + + switch(t) { - case (27): puts("1"); /* escape() ; */ - case (33): puts("2"); /* dosomething(); */ - case (42): puts("3"); /* something(); */ - default: puts("4"); /* stuff(); */ + + case (1): break; /* Ctrl a */ + case (2): break; /* Ctrl b */ + case (3): getch(); spec(h); break; /* Ctrl c */ + case (4): set(b, a); break; /* Printable chars. */ + case (5): delch(b); break; + case (6): break; + default: break; + } - -} + +} + +