#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
+#include "pd_readline.h"
/* This implementation of getch() is from here - */
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 */
/* Restore old terminal i/o settings */
-void resetTermios(void) {
+void resetTermios(void)
+{
tcsetattr(0, TCSANOW, &old);
}
-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)
{
- 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(); break; /* Ctrl c */
+ case (4): set(b, a); break; /* Printable chars. */
+ case (5): delch(b); break;
+ case (6): break;
+ default: break;
+
}
-
-}
+
+}
+
+