#include #include #include #define iota(x) 1 << (x) // ----------------------------------------------------------------------- // enums enum { KeyRune, KeyFunc, KeySym, KeyMouse, KeyPosition, KeyModeReport, KeyDCS, KeyOSC, /* add other recognised types here */ KeyUnknownCSI = -1 }; enum KeyEvent { EvNil, EvKey, EvEOF, EvAgain, EvErr, }; enum { SymUnknown = -1, SymNone = 0, /* special names in c0 */ SymBackspace, SymTab, SymEnter, SymEscape, /* special names in g0 */ SymSpace, SymDel, /* special keys */ SymUp, SymDown, SymLeft, SymRight, SymBegin, SymFind, SymInsert, SymDelete, SymSelect, SymPageUp, SymPageDown, SymHome, SymEnd, /* special keys from terminfo */ SymCancel, SymClear, SymClose, SymCommand, SymCopy, SymExit, SymHelp, SymMark, SymMessage, SymMove, SymOpen, SymOptions, SymPrint, SymRedo, SymReference, SymRefresh, SymReplace, SymRestart, SymResume, SymSave, SymSuspend, SymUndo, /* numeric keypad special keys */ SymKp0, SymKp1, SymKp2, SymKp3, SymKp4, SymKp5, SymKp6, SymKp7, SymKp8, SymKp9, SymKpEnter, SymKpPlus, SymKpMinus, SymKpMul, SymKpDiv, SymKpComma, SymKpDot, SymKpEq, /* et cetera ad nauseum */ NumSyms }; enum MouseEvent { MouseNil, MousePress, MouseDrag, MouseRelease, }; enum { ModShift = iota(0), ModAlt = iota(1), ModCtrl = iota(2), }; // ----------------------------------------------------------------------- // types typedef struct Input Input; struct Input { int fd; int wait; /* in msec */ struct { char *b, *c, bytes[1024]; } rbuf; /* read buffer */ struct { char *b, *c, bytes[1024]; } ebuf; /* escape buffer */ }; // ----------------------------------------------------------------------- // globals // ----------------------------------------------------------------------- // utility functions // ----------------------------------------------------------------------- // implementation Input * makeinput(int fd, int flags, unibi_term *info) { int i; Input *in; char *e; if (!(in = calloc(1, sizeof(in)))) panicf("out of memory"); in->fd = fd; in->wait = 50; /* in msec */ /* initialize buffers */ in->rbuf.c = in->rbuf.b = in->rbuf.bytes; return in; }