2011-03-30 21:32:51 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-03-20 21:38:23 +01:00
|
|
|
#ifndef GUARD_TERMKEY_H_
|
|
|
|
#define GUARD_TERMKEY_H_
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2008-11-16 13:28:38 +01:00
|
|
|
#define TERMKEY_VERSION_MAJOR @@VERSION_MAJOR@@
|
|
|
|
#define TERMKEY_VERSION_MINOR @@VERSION_MINOR@@
|
|
|
|
|
2008-11-16 13:40:14 +01:00
|
|
|
#define TERMKEY_CHECK_VERSION \
|
|
|
|
termkey_check_version(TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR)
|
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
typedef enum {
|
2008-02-07 02:17:59 +01:00
|
|
|
TERMKEY_SYM_UNKNOWN = -1,
|
|
|
|
TERMKEY_SYM_NONE = 0,
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
// Special names in C0
|
|
|
|
TERMKEY_SYM_BACKSPACE,
|
|
|
|
TERMKEY_SYM_TAB,
|
|
|
|
TERMKEY_SYM_ENTER,
|
|
|
|
TERMKEY_SYM_ESCAPE,
|
|
|
|
|
|
|
|
// Special names in G0
|
|
|
|
TERMKEY_SYM_SPACE,
|
|
|
|
TERMKEY_SYM_DEL,
|
|
|
|
|
2008-10-10 02:11:24 +02:00
|
|
|
// Special keys
|
2008-02-07 01:58:41 +01:00
|
|
|
TERMKEY_SYM_UP,
|
|
|
|
TERMKEY_SYM_DOWN,
|
|
|
|
TERMKEY_SYM_LEFT,
|
|
|
|
TERMKEY_SYM_RIGHT,
|
|
|
|
TERMKEY_SYM_BEGIN,
|
2008-02-23 20:22:28 +01:00
|
|
|
TERMKEY_SYM_FIND,
|
2008-02-07 01:58:41 +01:00
|
|
|
TERMKEY_SYM_INSERT,
|
|
|
|
TERMKEY_SYM_DELETE,
|
2008-02-23 20:22:28 +01:00
|
|
|
TERMKEY_SYM_SELECT,
|
2008-02-07 01:58:41 +01:00
|
|
|
TERMKEY_SYM_PAGEUP,
|
|
|
|
TERMKEY_SYM_PAGEDOWN,
|
2008-02-23 20:22:28 +01:00
|
|
|
TERMKEY_SYM_HOME,
|
|
|
|
TERMKEY_SYM_END,
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2008-10-10 02:11:24 +02:00
|
|
|
// Special keys from terminfo
|
|
|
|
TERMKEY_SYM_CANCEL,
|
|
|
|
TERMKEY_SYM_CLEAR,
|
|
|
|
TERMKEY_SYM_CLOSE,
|
|
|
|
TERMKEY_SYM_COMMAND,
|
|
|
|
TERMKEY_SYM_COPY,
|
|
|
|
TERMKEY_SYM_EXIT,
|
|
|
|
TERMKEY_SYM_HELP,
|
|
|
|
TERMKEY_SYM_MARK,
|
|
|
|
TERMKEY_SYM_MESSAGE,
|
|
|
|
TERMKEY_SYM_MOVE,
|
|
|
|
TERMKEY_SYM_OPEN,
|
|
|
|
TERMKEY_SYM_OPTIONS,
|
|
|
|
TERMKEY_SYM_PRINT,
|
|
|
|
TERMKEY_SYM_REDO,
|
|
|
|
TERMKEY_SYM_REFERENCE,
|
|
|
|
TERMKEY_SYM_REFRESH,
|
|
|
|
TERMKEY_SYM_REPLACE,
|
|
|
|
TERMKEY_SYM_RESTART,
|
|
|
|
TERMKEY_SYM_RESUME,
|
|
|
|
TERMKEY_SYM_SAVE,
|
|
|
|
TERMKEY_SYM_SUSPEND,
|
|
|
|
TERMKEY_SYM_UNDO,
|
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
// Numeric keypad special keys
|
|
|
|
TERMKEY_SYM_KP0,
|
|
|
|
TERMKEY_SYM_KP1,
|
|
|
|
TERMKEY_SYM_KP2,
|
|
|
|
TERMKEY_SYM_KP3,
|
|
|
|
TERMKEY_SYM_KP4,
|
|
|
|
TERMKEY_SYM_KP5,
|
|
|
|
TERMKEY_SYM_KP6,
|
|
|
|
TERMKEY_SYM_KP7,
|
|
|
|
TERMKEY_SYM_KP8,
|
|
|
|
TERMKEY_SYM_KP9,
|
|
|
|
TERMKEY_SYM_KPENTER,
|
|
|
|
TERMKEY_SYM_KPPLUS,
|
|
|
|
TERMKEY_SYM_KPMINUS,
|
|
|
|
TERMKEY_SYM_KPMULT,
|
|
|
|
TERMKEY_SYM_KPDIV,
|
|
|
|
TERMKEY_SYM_KPCOMMA,
|
|
|
|
TERMKEY_SYM_KPPERIOD,
|
|
|
|
TERMKEY_SYM_KPEQUALS,
|
|
|
|
|
|
|
|
// et cetera ad nauseum
|
2011-03-30 21:31:26 +02:00
|
|
|
TERMKEY_N_SYMS
|
2009-07-15 21:40:44 +02:00
|
|
|
} TermKeySym;
|
2008-02-07 02:17:59 +01:00
|
|
|
|
2008-08-21 21:05:17 +02:00
|
|
|
typedef enum {
|
|
|
|
TERMKEY_TYPE_UNICODE,
|
|
|
|
TERMKEY_TYPE_FUNCTION,
|
2009-11-24 02:22:55 +01:00
|
|
|
TERMKEY_TYPE_KEYSYM,
|
2011-03-30 21:31:26 +02:00
|
|
|
TERMKEY_TYPE_MOUSE
|
2009-07-15 21:40:44 +02:00
|
|
|
} TermKeyType;
|
2008-08-21 21:05:17 +02:00
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
typedef enum {
|
|
|
|
TERMKEY_RES_NONE,
|
|
|
|
TERMKEY_RES_KEY,
|
|
|
|
TERMKEY_RES_EOF,
|
2011-08-18 12:20:41 +02:00
|
|
|
TERMKEY_RES_AGAIN,
|
|
|
|
TERMKEY_RES_ERROR
|
2009-07-15 21:40:44 +02:00
|
|
|
} TermKeyResult;
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2009-11-27 15:36:29 +01:00
|
|
|
typedef enum {
|
|
|
|
TERMKEY_MOUSE_UNKNOWN,
|
|
|
|
TERMKEY_MOUSE_PRESS,
|
|
|
|
TERMKEY_MOUSE_DRAG,
|
2011-03-30 21:31:26 +02:00
|
|
|
TERMKEY_MOUSE_RELEASE
|
2009-11-27 15:36:29 +01:00
|
|
|
} TermKeyMouseEvent;
|
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
enum {
|
2008-11-03 22:23:59 +01:00
|
|
|
TERMKEY_KEYMOD_SHIFT = 1 << 0,
|
|
|
|
TERMKEY_KEYMOD_ALT = 1 << 1,
|
2011-03-30 21:31:26 +02:00
|
|
|
TERMKEY_KEYMOD_CTRL = 1 << 2
|
2008-02-07 01:58:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyType type;
|
2008-08-21 21:05:17 +02:00
|
|
|
union {
|
2009-07-15 21:40:44 +02:00
|
|
|
long codepoint; // TERMKEY_TYPE_UNICODE
|
|
|
|
int number; // TERMKEY_TYPE_FUNCTION
|
|
|
|
TermKeySym sym; // TERMKEY_TYPE_KEYSYM
|
2009-11-27 15:36:29 +01:00
|
|
|
char mouse[4]; // TERMKEY_TYPE_MOUSE
|
|
|
|
// opaque. see termkey_interpret_mouse
|
2008-08-21 21:05:17 +02:00
|
|
|
} code;
|
2009-11-27 15:36:29 +01:00
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
int modifiers;
|
|
|
|
|
2008-02-09 20:30:37 +01:00
|
|
|
/* Any Unicode character can be UTF-8 encoded in no more than 6 bytes, plus
|
2008-02-07 01:58:41 +01:00
|
|
|
* terminating NUL */
|
2008-02-09 20:30:37 +01:00
|
|
|
char utf8[7];
|
2009-07-15 21:40:44 +02:00
|
|
|
} TermKeyKey;
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
typedef struct _TermKey TermKey;
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
enum {
|
2011-03-23 23:17:25 +01:00
|
|
|
TERMKEY_FLAG_NOINTERPRET = 1 << 0, // Do not interpret C0//DEL codes if possible
|
2008-11-03 22:23:59 +01:00
|
|
|
TERMKEY_FLAG_CONVERTKP = 1 << 1, // Convert KP codes to regular keypresses
|
|
|
|
TERMKEY_FLAG_RAW = 1 << 2, // Input is raw bytes, not UTF-8
|
|
|
|
TERMKEY_FLAG_UTF8 = 1 << 3, // Input is definitely UTF-8
|
|
|
|
TERMKEY_FLAG_NOTERMIOS = 1 << 4, // Do not make initial termios calls on construction
|
2011-03-23 23:17:25 +01:00
|
|
|
TERMKEY_FLAG_SPACESYMBOL = 1 << 5, // Space is symbolic rather than Unicode
|
2011-08-25 11:48:41 +02:00
|
|
|
TERMKEY_FLAG_CTRLC = 1 << 6, // Allow Ctrl-C to be read as normal, disabling SIGINT
|
|
|
|
TERMKEY_FLAG_EINTR = 1 << 7 // Return ERROR on signal (EINTR) rather than retry
|
2008-02-07 01:58:41 +01:00
|
|
|
};
|
|
|
|
|
2008-11-16 13:40:14 +01:00
|
|
|
void termkey_check_version(int major, int minor);
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKey *termkey_new(int fd, int flags);
|
2011-03-31 12:06:21 +02:00
|
|
|
void termkey_free(TermKey *tk);
|
|
|
|
void termkey_destroy(TermKey *tk);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2011-03-31 12:06:21 +02:00
|
|
|
int termkey_get_fd(TermKey *tk);
|
2008-12-01 23:36:14 +01:00
|
|
|
|
2011-03-31 12:06:21 +02:00
|
|
|
int termkey_get_flags(TermKey *tk);
|
|
|
|
void termkey_set_flags(TermKey *tk, int newflags);
|
2008-11-10 22:21:19 +01:00
|
|
|
|
2011-03-31 12:06:21 +02:00
|
|
|
int termkey_get_waittime(TermKey *tk);
|
|
|
|
void termkey_set_waittime(TermKey *tk, int msec);
|
2008-02-10 21:22:33 +01:00
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key);
|
|
|
|
TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key);
|
|
|
|
TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2011-04-01 14:55:36 +02:00
|
|
|
void termkey_pushinput(TermKey *tk, const unsigned char *input, size_t inputlen);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyResult termkey_advisereadable(TermKey *tk);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name);
|
|
|
|
const char *termkey_get_keyname(TermKey *tk, TermKeySym sym);
|
2011-04-01 14:26:54 +02:00
|
|
|
char *termkey_lookup_keyname(TermKey *tk, const char *str, TermKeySym *sym);
|
2009-11-27 15:36:29 +01:00
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname);
|
2008-12-02 01:56:43 +01:00
|
|
|
|
2011-04-01 14:55:36 +02:00
|
|
|
TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKeyMouseEvent *event, int *button, int *line, int *col);
|
2011-04-01 14:26:54 +02:00
|
|
|
|
2008-10-06 23:02:12 +02:00
|
|
|
typedef enum {
|
2008-11-03 22:23:59 +01:00
|
|
|
TERMKEY_FORMAT_LONGMOD = 1 << 0, // Shift-... instead of S-...
|
|
|
|
TERMKEY_FORMAT_CARETCTRL = 1 << 1, // ^X instead of C-X
|
|
|
|
TERMKEY_FORMAT_ALTISMETA = 1 << 2, // Meta- or M- instead of Alt- or A-
|
|
|
|
TERMKEY_FORMAT_WRAPBRACKET = 1 << 3, // Wrap special keys in brackets like <Escape>
|
2009-11-27 16:07:05 +01:00
|
|
|
|
2011-03-30 21:31:26 +02:00
|
|
|
TERMKEY_FORMAT_MOUSE_POS = 1 << 8 // Include mouse position if relevant; @ col,line
|
2009-07-15 21:40:44 +02:00
|
|
|
} TermKeyFormat;
|
2008-10-06 23:02:12 +02:00
|
|
|
|
2008-10-06 23:39:35 +02:00
|
|
|
// Some useful combinations
|
|
|
|
|
|
|
|
#define TERMKEY_FORMAT_VIM (TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_WRAPBRACKET)
|
|
|
|
|
2011-04-01 14:49:20 +02:00
|
|
|
size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format);
|
|
|
|
char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format);
|
2011-03-31 12:08:43 +02:00
|
|
|
|
2011-04-02 16:07:30 +02:00
|
|
|
int termkey_keycmp(TermKey *tk, const TermKeyKey *key1, const TermKeyKey *key2);
|
|
|
|
|
2011-03-31 12:08:43 +02:00
|
|
|
// Old name for termkey_strfkey()
|
2009-07-15 21:40:44 +02:00
|
|
|
size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format);
|
|
|
|
|
|
|
|
// Legacy name typedefs
|
|
|
|
|
|
|
|
typedef TermKeySym termkey_keysym;
|
|
|
|
typedef TermKeyType termkey_type;
|
|
|
|
typedef TermKeyResult termkey_result;
|
|
|
|
typedef TermKeyKey termkey_key;
|
|
|
|
|
|
|
|
typedef TermKey termkey_t;
|
2008-08-21 21:20:07 +02:00
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
#endif
|
2011-03-30 21:32:51 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|