]> pd.if.org Git - pd_readline/blobdiff - keyhandler.c
More work
[pd_readline] / keyhandler.c
index 0130e9bf5829e9b3ef81db2b3bd4b1ad898912d0..f4ca5baa146f729885ca2d639f37cb52bde323d6 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdio.h> 
 #include <stdlib.h> 
 #include <termios.h>  
+#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,33 @@ 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        */ 
+
+void keyhandler(buf b, hist h) 
 { 
-  int i = getch(); 
+    
+  int a = getch();    
   
-  switch(i); 
+  int t = type(a); 
+    
+  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):   getch();  spec(h); break;   /*  Ctrl c  */     
+       case (4):   set(b, a);   break;    /*  Printable chars.  */    
+       case (5):   delch(b);  break;  
+       case (6):   break;  
+       default:    break; 
+                    
   }   
-  
-} 
+   
+}    
+
+