/* $OpenBSD$ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <limits.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "tmux.h"
/*
* Handle keys input from the outside terminal. tty_default_*_keys[] are a base
* table of supported keys which are looked up in terminfo(5) and translated
* into a ternary tree.
*/
static void tty_keys_add1(struct tty_key **, const char *, key_code);
static void tty_keys_add(struct tty *, const char *, key_code);
static void tty_keys_free1(struct tty_key *);
static struct tty_key *tty_keys_find1(struct tty_key *, const char *, size_t,
size_t *);
static struct tty_key *tty_keys_find(struct tty *, const char *, size_t,
size_t *);
static int tty_keys_next1(struct tty *, const char *, size_t, key_code *,
size_t *, int);
static void tty_keys_callback(int, short, void *);
static int tty_keys_mouse(struct tty *, const char *, size_t, size_t *,
struct mouse_event *);
static int tty_keys_clipboard(struct tty *, const char *, size_t,
size_t *);
static int tty_keys_device_attributes(struct tty *, const char *, size_t,
size_t *);
static int tty_keys_device_status_report(struct tty *, const char *,
size_t, size_t *);
/* Default raw keys. */
struct tty_default_key_raw {
const char *string;
key_code key;
};
static const struct tty_default_key_raw tty_default_raw_keys[] = {
/* Application escape. */
{ "\033O[", '\033' },
/*
* Numeric keypad. Just use the vt100 escape sequences here and always
* put the terminal into keypad_xmit mode. Translation of numbers
* mode/applications mode is done in input-keys.c.
*/
{ "\033Oo", KEYC_KP_SLASH },
{ "\033Oj", KEYC_KP_STAR },
{ "\033Om", KEYC_KP_MINUS },
{ "\033Ow", KEYC_KP_SEVEN },
{ "\033Ox", KEYC_KP_EIGHT },
{ "\033Oy", KEYC_KP_NINE },
{ "\033Ok", KEYC_KP_PLUS },
{ "\033Ot", KEYC_KP_FOUR },
{ "\033Ou", KEYC_KP_FIVE },
{ "\033Ov", KEYC_KP_SIX },
{ "\033Oq", KEYC_KP_ONE },
{ "\033Or", KEYC_KP_TWO },
{ "\033Os", KEYC_KP_THREE },
{ "\033OM", KEYC_KP_ENTER },
{ "\033Op", KEYC_KP_ZERO },
{ "\033On", KEYC_KP_PERIOD },
/* Arrow keys. */
{ "\033OA", KEYC_UP },
{ "\033OB", KEYC_DOWN },
{ "\033OC", KEYC_RIGHT },
{ "\033OD", KEYC_LEFT },
{ "\033[A", KEYC_UP },
{ "\033[B", KEYC_DOWN },
{ "\033