X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=keyhandler.c;h=2fc6ee5dd974f2dae10f8ebdcb9400d5505726b9;hb=2aac28bc15a87f5fde5daa83352f9f9b675fc635;hp=0130e9bf5829e9b3ef81db2b3bd4b1ad898912d0;hpb=36403b46c9eec27a672b0cfbfad9a79c7d153dca;p=pd_readline diff --git a/keyhandler.c b/keyhandler.c index 0130e9b..2fc6ee5 100644 --- a/keyhandler.c +++ b/keyhandler.c @@ -12,6 +12,7 @@ #include #include #include +#include "pd_readline.h" /* This implementation of getch() is from here - */ @@ -20,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 */ @@ -30,7 +32,8 @@ void initTermios(int echo) { /* Restore old terminal i/o settings */ -void resetTermios(void) { +void resetTermios(void) +{ tcsetattr(0, TCSANOW, &old); } @@ -58,19 +61,38 @@ char getche(void) { -int 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 */ + +/* TO DO: Use the helper function range */ +/* ( range(rstart, rend, val). ) */ +/* to handle entire ranges at once. */ + + +void keyhandler(buf b) { + int i = getch(); - switch(i); + int t = type(i); + + switch(t) { - case (27): escape() ; - case (33): dosomething(); - case (42): something(); - default: stuff(): + + case (1): break; /* Ctrl a */ + case (2): break; /* Ctrl b */ + case (3): break; /* Ctrl c */ + case (4): printf("%c", i); break; /* Printable chars. */ + case (5): delch(b); break; + case (6): break; + default: break; + } -} +} + +