From 6f84b07d939be6ef5e50c5468b95651fb4465500 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 12 Jun 2020 17:53:56 -0700 Subject: prototype of tinycurses --- sys/libterm/input.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 sys/libterm/input.c (limited to 'sys/libterm/input.c') diff --git a/sys/libterm/input.c b/sys/libterm/input.c new file mode 100644 index 0000000..038e8df --- /dev/null +++ b/sys/libterm/input.c @@ -0,0 +1,108 @@ +#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; +} -- cgit v1.2.1