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>
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
// CSI keys
|
|
|
|
TERMKEY_SYM_UP,
|
|
|
|
TERMKEY_SYM_DOWN,
|
|
|
|
TERMKEY_SYM_LEFT,
|
|
|
|
TERMKEY_SYM_RIGHT,
|
|
|
|
TERMKEY_SYM_BEGIN,
|
|
|
|
|
|
|
|
// CSI function keys
|
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
|
|
|
|
|
|
|
// 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
|
2008-02-07 02:17:59 +01:00
|
|
|
} termkey_sym;
|
|
|
|
|
2008-08-21 21:05:17 +02:00
|
|
|
typedef enum {
|
|
|
|
TERMKEY_TYPE_UNICODE,
|
|
|
|
TERMKEY_TYPE_FUNCTION,
|
|
|
|
TERMKEY_TYPE_KEYSYM
|
|
|
|
} termkey_type;
|
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
typedef enum {
|
|
|
|
TERMKEY_RES_NONE,
|
|
|
|
TERMKEY_RES_KEY,
|
|
|
|
TERMKEY_RES_EOF,
|
2008-02-10 20:23:18 +01:00
|
|
|
TERMKEY_RES_AGAIN,
|
2008-02-07 02:17:59 +01:00
|
|
|
} termkey_result;
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
TERMKEY_KEYMOD_SHIFT = 0x01,
|
|
|
|
TERMKEY_KEYMOD_ALT = 0x02,
|
|
|
|
TERMKEY_KEYMOD_CTRL = 0x04,
|
|
|
|
};
|
|
|
|
|
2008-02-10 18:41:13 +01:00
|
|
|
typedef int termkey_keysym;
|
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
typedef struct {
|
2008-08-21 21:05:17 +02:00
|
|
|
termkey_type type;
|
|
|
|
union {
|
|
|
|
int codepoint; // TERMKEY_TYPE_UNICODE
|
|
|
|
int number; // TERMKEY_TYPE_FUNCTION
|
|
|
|
termkey_keysym sym; // TERMKEY_TYPE_KEYSYM
|
|
|
|
} code;
|
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];
|
2008-02-07 01:58:41 +01:00
|
|
|
} termkey_key;
|
|
|
|
|
|
|
|
typedef struct termkey termkey_t;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TERMKEY_FLAG_NOINTERPRET = 0x01, // Do not interpret C0//G1 codes if possible
|
|
|
|
TERMKEY_FLAG_CONVERTKP = 0x02, // Convert KP codes to regular keypresses
|
2008-02-09 20:30:37 +01:00
|
|
|
TERMKEY_FLAG_RAW = 0x04, // Input is raw bytes, not UTF-8
|
|
|
|
TERMKEY_FLAG_UTF8 = 0x08, // Input is definitely UTF-8
|
2008-02-23 21:26:04 +01:00
|
|
|
TERMKEY_FLAG_NOTERMIOS = 0x10, // Do not make initial termios calls on construction
|
2008-02-07 01:58:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
termkey_t *termkey_new(int fd, int flags);
|
|
|
|
void termkey_free(termkey_t *tk);
|
2008-02-23 21:26:04 +01:00
|
|
|
void termkey_destroy(termkey_t *tk);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2008-02-10 21:22:33 +01:00
|
|
|
void termkey_setwaittime(termkey_t *tk, int msec);
|
|
|
|
int termkey_getwaittime(termkey_t *tk);
|
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
termkey_result termkey_getkey(termkey_t *tk, termkey_key *key);
|
2008-02-10 21:22:33 +01:00
|
|
|
termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key);
|
2008-02-07 02:17:59 +01:00
|
|
|
termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen);
|
|
|
|
|
2008-02-10 20:23:18 +01:00
|
|
|
termkey_result termkey_advisereadable(termkey_t *tk);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2008-08-21 21:05:17 +02:00
|
|
|
termkey_keysym termkey_register_keyname(termkey_t *tk, termkey_keysym sym, const char *name);
|
|
|
|
const char *termkey_get_keyname(termkey_t *tk, termkey_keysym sym);
|
|
|
|
|
2008-10-06 23:02:12 +02:00
|
|
|
typedef enum {
|
2008-10-06 23:22:09 +02:00
|
|
|
TERMKEY_FORMAT_LONGMOD = 1,
|
|
|
|
TERMKEY_FORMAT_CARETCTRL = 2,
|
|
|
|
TERMKEY_FORMAT_ALTISMETA = 4,
|
2008-10-06 23:33:49 +02:00
|
|
|
TERMKEY_FORMAT_WRAPBRACKET = 8,
|
2008-10-06 23:02:12 +02:00
|
|
|
} termkey_format;
|
|
|
|
|
2008-10-06 23:39:35 +02:00
|
|
|
// Some useful combinations
|
|
|
|
|
|
|
|
#define TERMKEY_FORMAT_VIM (TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_WRAPBRACKET)
|
|
|
|
|
2008-10-06 23:02:12 +02:00
|
|
|
size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format);
|
2008-08-21 21:20:07 +02:00
|
|
|
|
2008-02-07 01:58:41 +01:00
|
|
|
#endif
|