2014-09-23 01:38:08 +02:00
|
|
|
#ifndef TERMKEY_H
|
|
|
|
#define TERMKEY_H
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2014-09-23 01:38:08 +02:00
|
|
|
#include <limits.h>
|
2008-02-07 01:58:41 +01:00
|
|
|
|
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 \
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_check_version (TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR)
|
|
|
|
|
|
|
|
typedef enum termkey_sym termkey_sym_t;
|
|
|
|
enum termkey_sym
|
|
|
|
{
|
|
|
|
TERMKEY_SYM_UNKNOWN = -1,
|
|
|
|
TERMKEY_SYM_NONE = 0,
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
|
|
|
|
/* Special keys */
|
|
|
|
TERMKEY_SYM_UP,
|
|
|
|
TERMKEY_SYM_DOWN,
|
|
|
|
TERMKEY_SYM_LEFT,
|
|
|
|
TERMKEY_SYM_RIGHT,
|
|
|
|
TERMKEY_SYM_BEGIN,
|
|
|
|
TERMKEY_SYM_FIND,
|
|
|
|
TERMKEY_SYM_INSERT,
|
|
|
|
TERMKEY_SYM_DELETE,
|
|
|
|
TERMKEY_SYM_SELECT,
|
|
|
|
TERMKEY_SYM_PAGEUP,
|
|
|
|
TERMKEY_SYM_PAGEDOWN,
|
|
|
|
TERMKEY_SYM_HOME,
|
|
|
|
TERMKEY_SYM_END,
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
|
|
|
|
TERMKEY_N_SYMS
|
2008-02-07 01:58:41 +01:00
|
|
|
};
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef enum termkey_type termkey_type_t;
|
|
|
|
enum termkey_type
|
|
|
|
{
|
2014-09-28 03:51:45 +02:00
|
|
|
TERMKEY_TYPE_KEY,
|
2014-09-23 01:38:08 +02:00
|
|
|
TERMKEY_TYPE_FUNCTION,
|
|
|
|
TERMKEY_TYPE_KEYSYM,
|
|
|
|
TERMKEY_TYPE_MOUSE,
|
|
|
|
TERMKEY_TYPE_POSITION,
|
|
|
|
TERMKEY_TYPE_MODEREPORT,
|
|
|
|
/* add other recognised types here */
|
|
|
|
|
|
|
|
TERMKEY_TYPE_UNKNOWN_CSI = -1
|
2008-02-07 01:58:41 +01:00
|
|
|
};
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef enum termkey_result termkey_result_t;
|
|
|
|
enum termkey_result
|
|
|
|
{
|
|
|
|
TERMKEY_RES_NONE,
|
|
|
|
TERMKEY_RES_KEY,
|
|
|
|
TERMKEY_RES_EOF,
|
|
|
|
TERMKEY_RES_AGAIN,
|
|
|
|
TERMKEY_RES_ERROR
|
2011-08-28 18:50:18 +02:00
|
|
|
};
|
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef enum termkey_mouse_event termkey_mouse_event_t;
|
|
|
|
enum termkey_mouse_event
|
|
|
|
{
|
|
|
|
TERMKEY_MOUSE_UNKNOWN,
|
|
|
|
TERMKEY_MOUSE_PRESS,
|
|
|
|
TERMKEY_MOUSE_DRAG,
|
|
|
|
TERMKEY_MOUSE_RELEASE
|
|
|
|
};
|
2008-11-16 13:40:14 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TERMKEY_KEYMOD_SHIFT = 1 << 0,
|
|
|
|
TERMKEY_KEYMOD_ALT = 1 << 1,
|
|
|
|
TERMKEY_KEYMOD_CTRL = 1 << 2
|
|
|
|
};
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef struct termkey_key termkey_key_t;
|
|
|
|
struct termkey_key
|
|
|
|
{
|
|
|
|
termkey_type_t type;
|
|
|
|
union
|
|
|
|
{
|
2014-09-28 03:51:45 +02:00
|
|
|
uint32_t codepoint; /* TERMKEY_TYPE_KEY */
|
2014-09-23 01:38:08 +02:00
|
|
|
int number; /* TERMKEY_TYPE_FUNCTION */
|
|
|
|
termkey_sym_t sym; /* TERMKEY_TYPE_KEYSYM */
|
|
|
|
char mouse[4]; /* TERMKEY_TYPE_MOUSE */
|
|
|
|
/* opaque, see termkey_interpret_mouse() */
|
|
|
|
} code;
|
|
|
|
|
|
|
|
int modifiers;
|
|
|
|
|
|
|
|
/* The raw multibyte sequence for the key */
|
2014-09-28 03:51:45 +02:00
|
|
|
char multibyte[MB_LEN_MAX + 1];
|
2014-09-23 01:38:08 +02:00
|
|
|
};
|
2012-03-08 22:15:25 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef struct termkey termkey_t;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-09-28 03:51:45 +02:00
|
|
|
/* Do not interpret C0//DEL codes if possible */
|
|
|
|
TERMKEY_FLAG_NOINTERPRET = 1 << 0,
|
|
|
|
/* Convert KP codes to regular keypresses */
|
|
|
|
TERMKEY_FLAG_CONVERTKP = 1 << 1,
|
|
|
|
/* Don't try to decode the input characters */
|
|
|
|
TERMKEY_FLAG_RAW = 1 << 2,
|
|
|
|
/* Do not make initial termios calls on construction */
|
|
|
|
TERMKEY_FLAG_NOTERMIOS = 1 << 4,
|
|
|
|
/* Sets TERMKEY_CANON_SPACESYMBOL */
|
|
|
|
TERMKEY_FLAG_SPACESYMBOL = 1 << 5,
|
|
|
|
/* Allow Ctrl-C to be read as normal, disabling SIGINT */
|
|
|
|
TERMKEY_FLAG_CTRLC = 1 << 6,
|
|
|
|
/* Return ERROR on signal (EINTR) rather than retry */
|
|
|
|
TERMKEY_FLAG_EINTR = 1 << 7
|
2014-09-23 01:38:08 +02:00
|
|
|
};
|
2008-12-01 23:36:14 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TERMKEY_CANON_SPACESYMBOL = 1 << 0, /* Space is symbolic rather than Unicode */
|
|
|
|
TERMKEY_CANON_DELBS = 1 << 1 /* Del is converted to Backspace */
|
|
|
|
};
|
|
|
|
|
|
|
|
void termkey_check_version (int major, int minor);
|
2008-11-10 22:21:19 +01:00
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
termkey_t *termkey_new (int fd, const char *encoding, int flags);
|
|
|
|
termkey_t *termkey_new_abstract (const char *term,
|
|
|
|
const char *encoding, int flags);
|
2014-09-23 01:38:08 +02:00
|
|
|
void termkey_free (termkey_t *tk);
|
|
|
|
void termkey_destroy (termkey_t *tk);
|
2008-02-10 21:22:33 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_start (termkey_t *tk);
|
|
|
|
int termkey_stop (termkey_t *tk);
|
|
|
|
int termkey_is_started (termkey_t *tk);
|
2011-08-28 18:50:18 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_get_fd (termkey_t *tk);
|
2012-02-13 22:57:33 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_get_flags (termkey_t *tk);
|
|
|
|
void termkey_set_flags (termkey_t *tk, int newflags);
|
2012-01-18 11:04:15 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_get_waittime (termkey_t *tk);
|
|
|
|
void termkey_set_waittime (termkey_t *tk, int msec);
|
2011-08-27 20:59:02 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_get_canonflags (termkey_t *tk);
|
|
|
|
void termkey_set_canonflags (termkey_t *tk, int flags);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t termkey_get_buffer_size (termkey_t *tk);
|
|
|
|
int termkey_set_buffer_size (termkey_t *tk, size_t size);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t termkey_get_buffer_remaining (termkey_t *tk);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
void termkey_canonicalise (termkey_t *tk, termkey_key_t *key);
|
2009-11-27 15:36:29 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_result_t termkey_getkey (termkey_t *tk, termkey_key_t *key);
|
|
|
|
termkey_result_t termkey_getkey_force (termkey_t *tk, termkey_key_t *key);
|
|
|
|
termkey_result_t termkey_waitkey (termkey_t *tk, termkey_key_t *key);
|
2008-12-02 01:56:43 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_result_t termkey_advisereadable (termkey_t *tk);
|
2011-04-01 14:26:54 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t termkey_push_bytes (termkey_t *tk, const char *bytes, size_t len);
|
2012-04-24 18:27:48 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_sym_t termkey_register_keyname (termkey_t *tk,
|
|
|
|
termkey_sym_t sym, const char *name);
|
|
|
|
const char *termkey_get_keyname (termkey_t *tk, termkey_sym_t sym);
|
|
|
|
const char *termkey_lookup_keyname (termkey_t *tk,
|
|
|
|
const char *str, termkey_sym_t *sym);
|
2012-11-30 17:34:47 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_sym_t termkey_keyname2sym (termkey_t *tk, const char *keyname);
|
2012-11-30 15:35:23 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
termkey_result_t termkey_interpret_mouse (termkey_t *tk,
|
|
|
|
const termkey_key_t *key, termkey_mouse_event_t *event,
|
|
|
|
int *button, int *line, int *col);
|
|
|
|
termkey_result_t termkey_interpret_position (termkey_t *tk,
|
|
|
|
const termkey_key_t *key, int *line, int *col);
|
|
|
|
termkey_result_t termkey_interpret_modereport (termkey_t *tk,
|
|
|
|
const termkey_key_t *key, int *initial, int *mode, int *value);
|
|
|
|
termkey_result_t termkey_interpret_csi (termkey_t *tk,
|
|
|
|
const termkey_key_t *key, long args[], size_t *nargs, unsigned long *cmd);
|
2009-11-27 16:07:05 +01:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
typedef enum termkey_format termkey_format_t;
|
|
|
|
enum termkey_format
|
|
|
|
{
|
2014-09-28 03:51:45 +02:00
|
|
|
/* Shift-... instead of S-... */
|
|
|
|
TERMKEY_FORMAT_LONGMOD = 1 << 0,
|
|
|
|
/* ^X instead of C-X */
|
|
|
|
TERMKEY_FORMAT_CARETCTRL = 1 << 1,
|
|
|
|
/* Meta- or M- instead of Alt- or A- */
|
|
|
|
TERMKEY_FORMAT_ALTISMETA = 1 << 2,
|
|
|
|
/* Wrap special keys in brackets like <Escape> */
|
|
|
|
TERMKEY_FORMAT_WRAPBRACKET = 1 << 3,
|
|
|
|
/* M Foo instead of M-Foo */
|
|
|
|
TERMKEY_FORMAT_SPACEMOD = 1 << 4,
|
|
|
|
/* meta or m instead of Meta or M */
|
|
|
|
TERMKEY_FORMAT_LOWERMOD = 1 << 5,
|
|
|
|
/* page down instead of PageDown */
|
|
|
|
TERMKEY_FORMAT_LOWERSPACE = 1 << 6,
|
|
|
|
/* Include mouse position if relevant; @ col,line */
|
|
|
|
TERMKEY_FORMAT_MOUSE_POS = 1 << 8
|
2014-09-23 01:38:08 +02:00
|
|
|
};
|
2008-10-06 23:02:12 +02:00
|
|
|
|
2012-01-18 16:16:13 +01:00
|
|
|
/* Some useful combinations */
|
2008-10-06 23:39:35 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
#define TERMKEY_FORMAT_VIM (termkey_format_t) \
|
|
|
|
(TERMKEY_FORMAT_ALTISMETA | TERMKEY_FORMAT_WRAPBRACKET)
|
|
|
|
#define TERMKEY_FORMAT_URWID (termkey_format_t) \
|
|
|
|
(TERMKEY_FORMAT_LONGMOD | TERMKEY_FORMAT_ALTISMETA | \
|
|
|
|
TERMKEY_FORMAT_LOWERMOD | TERMKEY_FORMAT_SPACEMOD | \
|
|
|
|
TERMKEY_FORMAT_LOWERSPACE)
|
2008-10-06 23:39:35 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
size_t termkey_strfkey (termkey_t *tk, char *buffer, size_t len,
|
|
|
|
termkey_key_t *key, termkey_format_t format);
|
|
|
|
const char *termkey_strpkey (termkey_t *tk, const char *str,
|
|
|
|
termkey_key_t *key, termkey_format_t format);
|
2011-03-31 12:08:43 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
int termkey_keycmp (termkey_t *tk,
|
|
|
|
const termkey_key_t *key1, const termkey_key_t *key2);
|
2011-04-02 16:07:30 +02:00
|
|
|
|
2014-09-23 01:38:08 +02:00
|
|
|
#endif // ! TERMKEY_H
|
2011-03-30 21:32:51 +02:00
|
|
|
|