Rename to termo

This commit is contained in:
Přemysl Eric Janouch 2014-10-14 00:08:15 +02:00
parent e330d751a4
commit e98d9c0fd1
14 changed files with 1048 additions and 1048 deletions

View File

@ -1,4 +1,4 @@
project (termkey2 C)
project (termo C)
cmake_minimum_required (VERSION 2.8.5)
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
@ -18,9 +18,9 @@ set (project_VERSION ${project_VERSION}.${project_VERSION_PATCH})
set (project_API_VERSION ${project_VERSION_MAJOR})
# Names
set (project_LIB_NAME "termkey2-${project_API_VERSION}")
set (project_INCLUDE_NAME "termkey2-${project_API_VERSION}")
set (project_CMAKE_NAME "TermKey2")
set (project_LIB_NAME "termo-${project_API_VERSION}")
set (project_INCLUDE_NAME "termo-${project_API_VERSION}")
set (project_CMAKE_NAME "Termo")
# Dependecies
find_package (Curses)
@ -29,19 +29,19 @@ pkg_check_modules (glib glib-2.0 gio-2.0)
pkg_check_modules (unibilium unibilium>=0.1.0)
# Header files with configuration
configure_file (${PROJECT_SOURCE_DIR}/termkey2-config.h.in
${PROJECT_BINARY_DIR}/termkey2-config.h)
configure_file (${PROJECT_SOURCE_DIR}/termo-config.h.in
${PROJECT_BINARY_DIR}/termo-config.h)
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
# Project source files
set (lib_sources
termkey2.c
termo.c
driver-csi.c
driver-ti.c)
set (lib_headers
termkey2.h
termkey2-internal.h
${PROJECT_BINARY_DIR}/termkey2-config.h)
termo.h
termo-internal.h
${PROJECT_BINARY_DIR}/termo-config.h)
# Project libraries
if (unibilium_FOUND)
@ -56,33 +56,33 @@ else (CURSES_FOUND)
endif (unibilium_FOUND)
# Create the library targets
add_library (termkey2 SHARED ${lib_sources} ${lib_headers})
target_link_libraries (termkey2 ${lib_libraries})
set_target_properties (termkey2 PROPERTIES
add_library (termo SHARED ${lib_sources} ${lib_headers})
target_link_libraries (termo ${lib_libraries})
set_target_properties (termo PROPERTIES
OUTPUT_NAME ${project_LIB_NAME}
VERSION ${project_VERSION}
SOVERSION ${project_API_VERSION})
add_library (termkey2-static STATIC ${lib_sources} ${lib_headers})
target_link_libraries (termkey2-static ${lib_libraries})
set_target_properties (termkey2-static PROPERTIES
add_library (termo-static STATIC ${lib_sources} ${lib_headers})
target_link_libraries (termo-static ${lib_libraries})
set_target_properties (termo-static PROPERTIES
OUTPUT_NAME ${project_LIB_NAME}
VERSION ${project_VERSION}
SOVERSION ${project_API_VERSION})
# Demos
add_executable (demo-async EXCLUDE_FROM_ALL demo-async.c)
target_link_libraries (demo-async termkey2-static ${lib_libraries})
target_link_libraries (demo-async termo-static ${lib_libraries})
add_executable (demo EXCLUDE_FROM_ALL demo.c)
target_link_libraries (demo termkey2-static ${lib_libraries})
target_link_libraries (demo termo-static ${lib_libraries})
set (demos demo demo-async)
if (glib_FOUND)
include_directories (${glib_INCLUDE_DIRS})
add_executable (demo-glib EXCLUDE_FROM_ALL demo-glib.c)
target_link_libraries (demo
termkey2-static ${lib_libraries} ${glib_LIBRARIES})
termo-static ${lib_libraries} ${glib_LIBRARIES})
list (APPEND demos demo-glib)
endif (glib_FOUND)
@ -90,9 +90,9 @@ add_custom_target (demos DEPENDS ${demos})
# The files to be installed
include (GNUInstallDirs)
install (TARGETS termkey2 termkey2-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS termo termo-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
install (FILES termkey2.h ${PROJECT_BINARY_DIR}/termkey2-config.h
install (FILES termo.h ${PROJECT_BINARY_DIR}/termo-config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${project_INCLUDE_NAME})
# Configuration for other CMake projects

18
README
View File

@ -1,9 +1,9 @@
termkey2
========
termo
=====
`termkey2' is a library providing an alternative to ncurses' handling of
terminal input. ncurses does a really terrible job at that, mainly wrt. mouse
support which seems to be utterly broken. If you can drag things in a terminal
`termo' is a library providing an alternative to ncurses' handling of terminal
input. ncurses does a really terrible job at that, mainly wrt. mouse support
which seems to be utterly broken. If you can drag things in a terminal
application, such as in VIM, I can assure you it's not using ncurses for that.
Since terminal I/O is really complicated and full of special cases, this project
@ -17,7 +17,7 @@ Building and Installing
Build dependencies: GCC/Clang, pkg-config, cmake >= 2.8.5
Optional dependencies: Unibilium (alternative for curses), GLib (for the demos)
$ git clone https://github.com/pjanouch/termkey2.git
$ git clone https://github.com/pjanouch/termo.git
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
@ -27,7 +27,7 @@ To install the library, you can do either the usual:
Or you can try telling CMake to make a package for you. For Debian it is:
$ cpack -G DEB
# dpkg -i termkey2-*.deb
# dpkg -i termo-*.deb
To see the library in action, you can try running the demos, which are
statically linked against the library, and hence they can be run as they are:
@ -38,7 +38,7 @@ What's Different From the Original termkey?
-------------------------------------------
The main change is throwing away any UTF-8 dependent code, making the library
capable of handling all unibyte and multibyte encodings supported by iconv on
your system. The characters are still presented as Unicode at the end, however,
your system. The characters are still presented as Unicode in the end, however,
as the other sensible option is wchar_t and that doesn't really work well, see
http://gnu.org/software/libunistring/manual/libunistring.html#The-wchar_005ft-mess
@ -52,7 +52,7 @@ Oh, and I've deleted the manpages. It needs more Doxygen. :) TBD
License
-------
`termkey2' is based on the `termkey' library originally written by Paul Evans
`termo' is based on the `termkey' library originally written by Paul Evans
<leonerd@leonerd.org.uk>, with additional changes made by Přemysl Janouch
<p.janouch@gmail.com>.

View File

@ -4,5 +4,5 @@
# @project_CMAKE_NAME@_LIBRARIES
set (@project_CMAKE_NAME@_INCLUDE_DIRS @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/@project_INCLUDE_NAME@)
set (@project_CMAKE_NAME@_LIBRARIES termkey2)
set (@project_CMAKE_NAME@_LIBRARIES termo)

View File

@ -6,13 +6,13 @@
#include <unistd.h>
#include <locale.h>
#include "termkey2.h"
#include "termo.h"
static void
on_key (termkey_t *tk, termkey_key_t *key)
on_key (termo_t *tk, termo_key_t *key)
{
char buffer[50];
termkey_strfkey (tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM);
termo_strfkey (tk, buffer, sizeof buffer, key, TERMO_FORMAT_VIM);
printf ("%s\n", buffer);
}
@ -22,23 +22,23 @@ main (int argc, char *argv[])
(void) argc;
(void) argv;
TERMKEY_CHECK_VERSION;
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
termkey_t *tk = termkey_new (STDIN_FILENO, NULL, 0);
termo_t *tk = termo_new (STDIN_FILENO, NULL, 0);
if (!tk)
{
fprintf (stderr, "Cannot allocate termkey instance\n");
fprintf (stderr, "Cannot allocate termo instance\n");
exit (1);
}
struct pollfd fd;
fd.fd = STDIN_FILENO; /* the file descriptor we passed to termkey_new() */
fd.fd = STDIN_FILENO; /* the file descriptor we passed to termo_new() */
fd.events = POLLIN;
termkey_result_t ret;
termkey_key_t key;
termo_result_t ret;
termo_key_t key;
int running = 1;
int nextwait = -1;
@ -47,27 +47,27 @@ main (int argc, char *argv[])
{
if (poll (&fd, 1, nextwait) == 0)
// Timed out
if (termkey_getkey_force (tk, &key) == TERMKEY_RES_KEY)
if (termo_getkey_force (tk, &key) == TERMO_RES_KEY)
on_key (tk, &key);
if (fd.revents & (POLLIN | POLLHUP | POLLERR))
termkey_advisereadable (tk);
termo_advisereadable (tk);
while ((ret = termkey_getkey (tk, &key)) == TERMKEY_RES_KEY)
while ((ret = termo_getkey (tk, &key)) == TERMO_RES_KEY)
{
on_key (tk, &key);
if (key.type == TERMKEY_TYPE_KEY
&& (key.modifiers & TERMKEY_KEYMOD_CTRL)
if (key.type == TERMO_TYPE_KEY
&& (key.modifiers & TERMO_KEYMOD_CTRL)
&& (key.code.codepoint == 'C' || key.code.codepoint == 'c'))
running = 0;
}
if (ret == TERMKEY_RES_AGAIN)
nextwait = termkey_get_waittime (tk);
if (ret == TERMO_RES_AGAIN)
nextwait = termo_get_waittime (tk);
else
nextwait = -1;
}
termkey_destroy (tk);
termo_destroy (tk);
}

View File

@ -3,24 +3,24 @@
#include <unistd.h>
#include <locale.h>
#include "termkey2.h"
#include "termo.h"
static termkey_t *tk;
static termo_t *tk;
static int timeout_id;
static void
on_key (termkey_t *tk, termkey_key_t *key)
on_key (termo_t *tk, termo_key_t *key)
{
char buffer[50];
termkey_strfkey (tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM);
termo_strfkey (tk, buffer, sizeof buffer, key, TERMO_FORMAT_VIM);
printf ("%s\n", buffer);
}
static gboolean
key_timer (gpointer data)
{
termkey_key_t key;
if (termkey_getkey_force (tk, &key) == TERMKEY_RES_KEY)
termo_key_t key;
if (termo_getkey_force (tk, &key) == TERMO_RES_KEY)
on_key (tk, &key);
return FALSE;
}
@ -33,16 +33,16 @@ stdin_io (GIOChannel *source, GIOCondition condition, gpointer data)
if (timeout_id)
g_source_remove (timeout_id);
termkey_advisereadable (tk);
termo_advisereadable (tk);
termkey_result_t ret;
termkey_key_t key;
while ((ret = termkey_getkey (tk, &key)) == TERMKEY_RES_KEY)
termo_result_t ret;
termo_key_t key;
while ((ret = termo_getkey (tk, &key)) == TERMO_RES_KEY)
on_key (tk, &key);
if (ret == TERMKEY_RES_AGAIN)
if (ret == TERMO_RES_AGAIN)
timeout_id = g_timeout_add
(termkey_get_waittime (tk), key_timer, NULL);
(termo_get_waittime (tk), key_timer, NULL);
}
return TRUE;
@ -54,13 +54,13 @@ main (int argc, char *argv[])
(void) argc;
(void) argv;
TERMKEY_CHECK_VERSION;
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
tk = termkey_new (STDIN_FILENO, NULL, 0);
tk = termo_new (STDIN_FILENO, NULL, 0);
if (!tk)
{
fprintf (stderr, "Cannot allocate termkey instance\n");
fprintf (stderr, "Cannot allocate termo instance\n");
exit (1);
}
@ -68,5 +68,5 @@ main (int argc, char *argv[])
g_io_add_watch (g_io_channel_unix_new (STDIN_FILENO),
G_IO_IN, stdin_io, NULL);
g_main_loop_run (loop);
termkey_destroy (tk);
termo_destroy (tk);
}

54
demo.c
View File

@ -6,20 +6,20 @@
#include <errno.h>
#include <locale.h>
#include "termkey2.h"
#include "termo.h"
int
main(int argc, char *argv[])
{
TERMKEY_CHECK_VERSION;
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
int mouse = 0;
int mouse_proto = 0;
termkey_format_t format = TERMKEY_FORMAT_VIM;
termo_format_t format = TERMO_FORMAT_VIM;
char buffer[50];
termkey_t *tk;
termo_t *tk;
int opt;
while ((opt = getopt (argc, argv, "m::p:")) != -1)
@ -43,21 +43,21 @@ main(int argc, char *argv[])
}
}
tk = termkey_new (STDIN_FILENO, NULL,
TERMKEY_FLAG_SPACESYMBOL | TERMKEY_FLAG_CTRLC);
tk = termo_new (STDIN_FILENO, NULL,
TERMO_FLAG_SPACESYMBOL | TERMO_FLAG_CTRLC);
if (!tk)
{
fprintf (stderr, "Cannot allocate termkey instance\n");
fprintf (stderr, "Cannot allocate termo instance\n");
exit (1);
}
if (termkey_get_flags (tk) & TERMKEY_FLAG_RAW)
if (termo_get_flags (tk) & TERMO_FLAG_RAW)
printf ("Termkey in RAW mode\n");
else
printf ("Termkey in multibyte mode\n");
termkey_result_t ret;
termkey_key_t key;
termo_result_t ret;
termo_key_t key;
if (mouse)
{
@ -66,38 +66,38 @@ main(int argc, char *argv[])
printf ("\033[?%dh", mouse_proto);
}
while ((ret = termkey_waitkey (tk, &key)) != TERMKEY_RES_EOF)
while ((ret = termo_waitkey (tk, &key)) != TERMO_RES_EOF)
{
if (ret == TERMKEY_RES_KEY)
if (ret == TERMO_RES_KEY)
{
termkey_strfkey (tk, buffer, sizeof buffer, &key, format);
if (key.type == TERMKEY_TYPE_MOUSE)
termo_strfkey (tk, buffer, sizeof buffer, &key, format);
if (key.type == TERMO_TYPE_MOUSE)
{
int line, col;
termkey_interpret_mouse (tk, &key, NULL, NULL, &line, &col);
termo_interpret_mouse (tk, &key, NULL, NULL, &line, &col);
printf ("%s at line=%d, col=%d\n", buffer, line, col);
}
else if (key.type == TERMKEY_TYPE_POSITION)
else if (key.type == TERMO_TYPE_POSITION)
{
int line, col;
termkey_interpret_position (tk, &key, &line, &col);
termo_interpret_position (tk, &key, &line, &col);
printf ("Cursor position report at line=%d, col=%d\n",
line, col);
}
else if (key.type == TERMKEY_TYPE_MODEREPORT)
else if (key.type == TERMO_TYPE_MODEREPORT)
{
int initial, mode, value;
termkey_interpret_modereport
termo_interpret_modereport
(tk, &key, &initial, &mode, &value);
printf ("Mode report %s mode %d = %d\n",
initial ? "DEC" : "ANSI", mode, value);
}
else if (key.type == TERMKEY_TYPE_UNKNOWN_CSI)
else if (key.type == TERMO_TYPE_UNKNOWN_CSI)
{
long args[16];
size_t nargs = 16;
unsigned long command;
termkey_interpret_csi (tk, &key, args, &nargs, &command);
termo_interpret_csi (tk, &key, args, &nargs, &command);
printf ("Unrecognised CSI %c %ld;%ld %c%c\n",
(char) (command >> 8), args[0], args[1],
(char) (command >> 16), (char) command);
@ -105,12 +105,12 @@ main(int argc, char *argv[])
else
printf ("Key %s\n", buffer);
if (key.type == TERMKEY_TYPE_KEY
&& key.modifiers & TERMKEY_KEYMOD_CTRL
if (key.type == TERMO_TYPE_KEY
&& key.modifiers & TERMO_KEYMOD_CTRL
&& (key.code.codepoint == 'C' || key.code.codepoint == 'c'))
break;
if (key.type == TERMKEY_TYPE_KEY
if (key.type == TERMO_TYPE_KEY
&& key.modifiers == 0
&& key.code.codepoint == '?')
{
@ -119,11 +119,11 @@ main(int argc, char *argv[])
fflush (stdout);
}
}
else if (ret == TERMKEY_RES_ERROR)
else if (ret == TERMO_RES_ERROR)
{
if (errno != EINTR)
{
perror ("termkey_waitkey");
perror ("termo_waitkey");
break;
}
printf ("Interrupted by signal\n");
@ -133,5 +133,5 @@ main(int argc, char *argv[])
if (mouse)
printf ("\033[?%dlMouse mode deactivated\n", mouse);
termkey_destroy (tk);
termo_destroy (tk);
}

View File

@ -1,5 +1,5 @@
#include "termkey2.h"
#include "termkey2-internal.h"
#include "termo.h"
#include "termo-internal.h"
#include <stdio.h>
#include <string.h>
@ -11,12 +11,12 @@ static char ss3_kpalts[64];
typedef struct
{
termkey_t *tk;
termo_t *tk;
}
termkey_csi_t;
termo_csi_t;
typedef termkey_result_t (*csi_handler_fn)
(termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args);
typedef termo_result_t (*csi_handler_fn)
(termo_t *tk, termo_key_t *key, int cmd, long *arg, int args);
static csi_handler_fn csi_handlers[64];
/*
@ -25,9 +25,9 @@ static csi_handler_fn csi_handlers[64];
static struct keyinfo csi_ss3s[64];
static termkey_result_t
handle_csi_ss3_full (termkey_t *tk,
termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_ss3_full (termo_t *tk,
termo_key_t *key, int cmd, long *arg, int args)
{
(void) tk;
@ -41,13 +41,13 @@ handle_csi_ss3_full (termkey_t *tk,
key->modifiers &= ~(csi_ss3s[cmd - 0x40].modifier_mask);
key->modifiers |= csi_ss3s[cmd - 0x40].modifier_set;
if (key->code.sym == TERMKEY_SYM_UNKNOWN)
return TERMKEY_RES_NONE;
return TERMKEY_RES_KEY;
if (key->code.sym == TERMO_SYM_UNKNOWN)
return TERMO_RES_NONE;
return TERMO_RES_KEY;
}
static void
register_csi_ss3_full (termkey_type_t type, termkey_sym_t sym,
register_csi_ss3_full (termo_type_t type, termo_sym_t sym,
int modifier_set, int modifier_mask, unsigned char cmd)
{
if (cmd < 0x40 || cmd >= 0x80)
@ -62,7 +62,7 @@ register_csi_ss3_full (termkey_type_t type, termkey_sym_t sym,
}
static void
register_csi_ss3 (termkey_type_t type, termkey_sym_t sym, unsigned char cmd)
register_csi_ss3 (termo_type_t type, termo_sym_t sym, unsigned char cmd)
{
register_csi_ss3_full (type, sym, 0, 0, cmd);
}
@ -72,7 +72,7 @@ register_csi_ss3 (termkey_type_t type, termkey_sym_t sym, unsigned char cmd)
*/
static void
register_ss3kpalt (termkey_type_t type, termkey_sym_t sym,
register_ss3kpalt (termo_type_t type, termo_sym_t sym,
unsigned char cmd, char kpalt)
{
if (cmd < 0x40 || cmd >= 0x80)
@ -94,8 +94,8 @@ register_ss3kpalt (termkey_type_t type, termkey_sym_t sym,
static struct keyinfo csifuncs[35];
#define NCSIFUNCS ((long) (sizeof csifuncs / sizeof csifuncs[0]))
static termkey_result_t
handle_csifunc (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csifunc (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
{
(void) cmd;
@ -103,7 +103,7 @@ handle_csifunc (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
key->modifiers = arg[1] - 1;
else
key->modifiers = 0;
key->type = TERMKEY_TYPE_KEYSYM;
key->type = TERMO_TYPE_KEYSYM;
if (arg[0] == 27)
{
@ -119,21 +119,21 @@ handle_csifunc (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
key->modifiers |= csifuncs[arg[0]].modifier_set;
}
else
key->code.sym = TERMKEY_SYM_UNKNOWN;
key->code.sym = TERMO_SYM_UNKNOWN;
if (key->code.sym == TERMKEY_SYM_UNKNOWN)
if (key->code.sym == TERMO_SYM_UNKNOWN)
{
#ifdef DEBUG
fprintf (stderr, "CSI: Unknown function key %ld\n", arg[0]);
#endif
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
static void
register_csifunc (termkey_type_t type, termkey_sym_t sym, int number)
register_csifunc (termo_type_t type, termo_sym_t sym, int number)
{
if (number >= NCSIFUNCS)
return;
@ -150,21 +150,21 @@ register_csifunc (termkey_type_t type, termkey_sym_t sym, int number)
* URxvt seems to emit this instead of ~ when holding Ctrl
*/
static termkey_result_t
handle_csi_caret (termkey_t *tk,
termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_caret (termo_t *tk,
termo_key_t *key, int cmd, long *arg, int args)
{
switch (cmd)
{
case '^':
{
termkey_result_t res = handle_csifunc (tk, key, cmd, arg, args);
if (res == TERMKEY_RES_KEY)
key->modifiers |= TERMKEY_KEYMOD_CTRL;
termo_result_t res = handle_csifunc (tk, key, cmd, arg, args);
if (res == TERMO_RES_KEY)
key->modifiers |= TERMO_KEYMOD_CTRL;
return res;
}
default:
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
}
@ -172,8 +172,8 @@ handle_csi_caret (termkey_t *tk,
* Handler for CSI u extended Unicode keys
*/
static termkey_result_t
handle_csi_u (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_u (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
{
switch (cmd)
{
@ -185,13 +185,13 @@ handle_csi_u (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
key->modifiers = 0;
int mod = key->modifiers;
key->type = TERMKEY_TYPE_KEYSYM;
key->type = TERMO_TYPE_KEYSYM;
(*tk->method.emit_codepoint) (tk, arg[0], key);
key->modifiers |= mod;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
default:
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
}
@ -200,8 +200,8 @@ handle_csi_u (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
* Note: This does not handle X10 encoding
*/
static termkey_result_t
handle_csi_m (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_m (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
{
(void) tk;
@ -214,57 +214,57 @@ handle_csi_m (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
case 'm':
break;
default:
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
if (!initial && args >= 3)
{
// rxvt protocol
key->type = TERMKEY_TYPE_MOUSE;
key->type = TERMO_TYPE_MOUSE;
key->code.mouse.info = arg[0] - 0x20;
key->modifiers = (key->code.mouse.info & 0x1c) >> 2;
key->code.mouse.info &= ~0x1c;
termkey_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
return TERMKEY_RES_KEY;
termo_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
return TERMO_RES_KEY;
}
if (initial == '<' && args >= 3)
{
// SGR protocol
key->type = TERMKEY_TYPE_MOUSE;
key->type = TERMO_TYPE_MOUSE;
key->code.mouse.info = arg[0];
key->modifiers = (key->code.mouse.info & 0x1c) >> 2;
key->code.mouse.info &= ~0x1c;
termkey_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
termo_key_set_linecol (key, arg[2] - 1, arg[1] - 1);
if (cmd == 'm') // release
key->code.mouse.info |= 0x8000;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
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)
termo_result_t
termo_interpret_mouse (termo_t *tk, const termo_key_t *key,
termo_mouse_event_t *event, int *button, int *line, int *col)
{
(void) tk;
if (key->type != TERMKEY_TYPE_MOUSE)
return TERMKEY_RES_NONE;
if (key->type != TERMO_TYPE_MOUSE)
return TERMO_RES_NONE;
if (button)
*button = 0;
termkey_key_get_linecol (key, line, col);
termo_key_get_linecol (key, line, col);
// XXX: WTF is this logic?
if (!event)
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
int btn = 0;
int code = key->code.mouse.info;
@ -276,30 +276,30 @@ termkey_interpret_mouse (termkey_t *tk, const termkey_key_t *key,
case 0:
case 1:
case 2:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
*event = drag ? TERMO_MOUSE_DRAG : TERMO_MOUSE_PRESS;
btn = code + 1;
break;
case 3:
*event = TERMKEY_MOUSE_RELEASE;
*event = TERMO_MOUSE_RELEASE;
// no button hint
break;
case 64:
case 65:
*event = drag ? TERMKEY_MOUSE_DRAG : TERMKEY_MOUSE_PRESS;
*event = drag ? TERMO_MOUSE_DRAG : TERMO_MOUSE_PRESS;
btn = code + 4 - 64;
break;
default:
*event = TERMKEY_MOUSE_UNKNOWN;
*event = TERMO_MOUSE_UNKNOWN;
}
if (button)
*button = btn;
if (key->code.mouse.info & 0x8000)
*event = TERMKEY_MOUSE_RELEASE;
return TERMKEY_RES_KEY;
*event = TERMO_MOUSE_RELEASE;
return TERMO_RES_KEY;
}
/*
@ -307,43 +307,43 @@ termkey_interpret_mouse (termkey_t *tk, const termkey_key_t *key,
* A plain CSI R with no arguments is probably actually <F3>
*/
static termkey_result_t
handle_csi_R (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_R (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
{
switch (cmd)
{
case 'R' | '?' << 8:
if (args < 2)
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
key->type = TERMKEY_TYPE_POSITION;
termkey_key_set_linecol (key, arg[1], arg[0]);
return TERMKEY_RES_KEY;
key->type = TERMO_TYPE_POSITION;
termo_key_set_linecol (key, arg[1], arg[0]);
return TERMO_RES_KEY;
default:
return handle_csi_ss3_full (tk, key, cmd, arg, args);
}
}
termkey_result_t
termkey_interpret_position (termkey_t *tk,
const termkey_key_t *key, int *line, int *col)
termo_result_t
termo_interpret_position (termo_t *tk,
const termo_key_t *key, int *line, int *col)
{
(void) tk;
if (key->type != TERMKEY_TYPE_POSITION)
return TERMKEY_RES_NONE;
if (key->type != TERMO_TYPE_POSITION)
return TERMO_RES_NONE;
termkey_key_get_linecol (key, line, col);
return TERMKEY_RES_KEY;
termo_key_get_linecol (key, line, col);
return TERMO_RES_KEY;
}
/*
* Handler for CSI $y mode status reports
*/
static termkey_result_t
handle_csi_y (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
static termo_result_t
handle_csi_y (termo_t *tk, termo_key_t *key, int cmd, long *arg, int args)
{
(void) tk;
@ -352,27 +352,27 @@ handle_csi_y (termkey_t *tk, termkey_key_t *key, int cmd, long *arg, int args)
case 'y' | '$' << 16:
case 'y' | '$' << 16 | '?' << 8:
if (args < 2)
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
key->type = TERMKEY_TYPE_MODEREPORT;
key->type = TERMO_TYPE_MODEREPORT;
key->code.mode.initial = (cmd >> 8);
key->code.mode.mode = arg[0];
key->code.mode.value = arg[1];
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
default:
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
}
termkey_result_t
termkey_interpret_modereport (termkey_t *tk,
const termkey_key_t *key, int *initial, int *mode, int *value)
termo_result_t
termo_interpret_modereport (termo_t *tk,
const termo_key_t *key, int *initial, int *mode, int *value)
{
(void) tk;
if (key->type != TERMKEY_TYPE_MODEREPORT)
return TERMKEY_RES_NONE;
if (key->type != TERMO_TYPE_MODEREPORT)
return TERMO_RES_NONE;
if (initial)
*initial = key->code.mode.initial;
@ -380,13 +380,13 @@ termkey_interpret_modereport (termkey_t *tk,
*mode = key->code.mode.mode;
if (value)
*value = key->code.mode.value;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
static termkey_result_t
parse_csi (termkey_t *tk, size_t introlen, size_t *csi_len,
static termo_result_t
parse_csi (termo_t *tk, size_t introlen, size_t *csi_len,
long args[], size_t *nargs, unsigned long *commandp)
{
size_t csi_end = introlen;
@ -398,7 +398,7 @@ parse_csi (termkey_t *tk, size_t introlen, size_t *csi_len,
}
if (csi_end >= tk->buffcount)
return TERMKEY_RES_AGAIN;
return TERMO_RES_AGAIN;
unsigned char cmd = CHARAT (csi_end);
*commandp = cmd;
@ -451,17 +451,17 @@ parse_csi (termkey_t *tk, size_t introlen, size_t *csi_len,
*nargs = argi;
*csi_len = csi_end + 1;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
termkey_result_t
termkey_interpret_csi (termkey_t *tk, const termkey_key_t *key,
termo_result_t
termo_interpret_csi (termo_t *tk, const termo_key_t *key,
long args[], size_t *nargs, unsigned long *cmd)
{
if (tk->hightide == 0)
return TERMKEY_RES_NONE;
if (key->type != TERMKEY_TYPE_UNKNOWN_CSI)
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
if (key->type != TERMO_TYPE_UNKNOWN_CSI)
return TERMO_RES_NONE;
size_t dummy;
return parse_csi (tk, 0, &dummy, args, nargs, cmd);
@ -473,76 +473,76 @@ register_keys (void)
int i;
for (i = 0; i < 64; i++)
{
csi_ss3s[i].sym = TERMKEY_SYM_UNKNOWN;
ss3s[i].sym = TERMKEY_SYM_UNKNOWN;
csi_ss3s[i].sym = TERMO_SYM_UNKNOWN;
ss3s[i].sym = TERMO_SYM_UNKNOWN;
ss3_kpalts[i] = 0;
}
for (i = 0; i < NCSIFUNCS; i++)
csifuncs[i].sym = TERMKEY_SYM_UNKNOWN;
csifuncs[i].sym = TERMO_SYM_UNKNOWN;
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_UP, 'A');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DOWN, 'B');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RIGHT, 'C');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_LEFT, 'D');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BEGIN, 'E');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_END, 'F');
register_csi_ss3 (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HOME, 'H');
register_csi_ss3 (TERMKEY_TYPE_FUNCTION, 1, 'P');
register_csi_ss3 (TERMKEY_TYPE_FUNCTION, 2, 'Q');
register_csi_ss3 (TERMKEY_TYPE_FUNCTION, 3, 'R');
register_csi_ss3 (TERMKEY_TYPE_FUNCTION, 4, 'S');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_UP, 'A');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_DOWN, 'B');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_RIGHT, 'C');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_LEFT, 'D');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_BEGIN, 'E');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_END, 'F');
register_csi_ss3 (TERMO_TYPE_KEYSYM, TERMO_SYM_HOME, 'H');
register_csi_ss3 (TERMO_TYPE_FUNCTION, 1, 'P');
register_csi_ss3 (TERMO_TYPE_FUNCTION, 2, 'Q');
register_csi_ss3 (TERMO_TYPE_FUNCTION, 3, 'R');
register_csi_ss3 (TERMO_TYPE_FUNCTION, 4, 'S');
register_csi_ss3_full (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_TAB,
TERMKEY_KEYMOD_SHIFT, TERMKEY_KEYMOD_SHIFT, 'Z');
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_TAB,
TERMO_KEYMOD_SHIFT, TERMO_KEYMOD_SHIFT, 'Z');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPENTER, 'M', 0);
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPEQUALS, 'X', '=');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPMULT, 'j', '*');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPPLUS, 'k', '+');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPCOMMA, 'l', ',');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPMINUS, 'm', '-');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPPERIOD, 'n', '.');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KPDIV, 'o', '/');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP0, 'p', '0');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP1, 'q', '1');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP2, 'r', '2');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP3, 's', '3');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP4, 't', '4');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP5, 'u', '5');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP6, 'v', '6');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP7, 'w', '7');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP8, 'x', '8');
register_ss3kpalt (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_KP9, 'y', '9');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPENTER, 'M', 0);
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPEQUALS, 'X', '=');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPMULT, 'j', '*');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPPLUS, 'k', '+');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPCOMMA, 'l', ',');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPMINUS, 'm', '-');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPPERIOD, 'n', '.');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KPDIV, 'o', '/');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP0, 'p', '0');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP1, 'q', '1');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP2, 'r', '2');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP3, 's', '3');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP4, 't', '4');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP5, 'u', '5');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP6, 'v', '6');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP7, 'w', '7');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP8, 'x', '8');
register_ss3kpalt (TERMO_TYPE_KEYSYM, TERMO_SYM_KP9, 'y', '9');
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_FIND, 1);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_INSERT, 2);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DELETE, 3);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_SELECT, 4);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEUP, 5);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEDOWN, 6);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HOME, 7);
register_csifunc (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_END, 8);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_FIND, 1);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_INSERT, 2);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_DELETE, 3);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_SELECT, 4);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEUP, 5);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEDOWN, 6);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_HOME, 7);
register_csifunc (TERMO_TYPE_KEYSYM, TERMO_SYM_END, 8);
register_csifunc (TERMKEY_TYPE_FUNCTION, 1, 11);
register_csifunc (TERMKEY_TYPE_FUNCTION, 2, 12);
register_csifunc (TERMKEY_TYPE_FUNCTION, 3, 13);
register_csifunc (TERMKEY_TYPE_FUNCTION, 4, 14);
register_csifunc (TERMKEY_TYPE_FUNCTION, 5, 15);
register_csifunc (TERMKEY_TYPE_FUNCTION, 6, 17);
register_csifunc (TERMKEY_TYPE_FUNCTION, 7, 18);
register_csifunc (TERMKEY_TYPE_FUNCTION, 8, 19);
register_csifunc (TERMKEY_TYPE_FUNCTION, 9, 20);
register_csifunc (TERMKEY_TYPE_FUNCTION, 10, 21);
register_csifunc (TERMKEY_TYPE_FUNCTION, 11, 23);
register_csifunc (TERMKEY_TYPE_FUNCTION, 12, 24);
register_csifunc (TERMKEY_TYPE_FUNCTION, 13, 25);
register_csifunc (TERMKEY_TYPE_FUNCTION, 14, 26);
register_csifunc (TERMKEY_TYPE_FUNCTION, 15, 28);
register_csifunc (TERMKEY_TYPE_FUNCTION, 16, 29);
register_csifunc (TERMKEY_TYPE_FUNCTION, 17, 31);
register_csifunc (TERMKEY_TYPE_FUNCTION, 18, 32);
register_csifunc (TERMKEY_TYPE_FUNCTION, 19, 33);
register_csifunc (TERMKEY_TYPE_FUNCTION, 20, 34);
register_csifunc (TERMO_TYPE_FUNCTION, 1, 11);
register_csifunc (TERMO_TYPE_FUNCTION, 2, 12);
register_csifunc (TERMO_TYPE_FUNCTION, 3, 13);
register_csifunc (TERMO_TYPE_FUNCTION, 4, 14);
register_csifunc (TERMO_TYPE_FUNCTION, 5, 15);
register_csifunc (TERMO_TYPE_FUNCTION, 6, 17);
register_csifunc (TERMO_TYPE_FUNCTION, 7, 18);
register_csifunc (TERMO_TYPE_FUNCTION, 8, 19);
register_csifunc (TERMO_TYPE_FUNCTION, 9, 20);
register_csifunc (TERMO_TYPE_FUNCTION, 10, 21);
register_csifunc (TERMO_TYPE_FUNCTION, 11, 23);
register_csifunc (TERMO_TYPE_FUNCTION, 12, 24);
register_csifunc (TERMO_TYPE_FUNCTION, 13, 25);
register_csifunc (TERMO_TYPE_FUNCTION, 14, 26);
register_csifunc (TERMO_TYPE_FUNCTION, 15, 28);
register_csifunc (TERMO_TYPE_FUNCTION, 16, 29);
register_csifunc (TERMO_TYPE_FUNCTION, 17, 31);
register_csifunc (TERMO_TYPE_FUNCTION, 18, 32);
register_csifunc (TERMO_TYPE_FUNCTION, 19, 33);
register_csifunc (TERMO_TYPE_FUNCTION, 20, 34);
csi_handlers['u' - 0x40] = &handle_csi_u;
@ -554,14 +554,14 @@ register_keys (void)
csi_handlers['y' - 0x40] = &handle_csi_y;
// URxvt
register_csi_ss3_full (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_UP,
TERMKEY_KEYMOD_CTRL, TERMKEY_KEYMOD_CTRL, 'a');
register_csi_ss3_full (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DOWN,
TERMKEY_KEYMOD_CTRL, TERMKEY_KEYMOD_CTRL, 'b');
register_csi_ss3_full (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RIGHT,
TERMKEY_KEYMOD_CTRL, TERMKEY_KEYMOD_CTRL, 'c');
register_csi_ss3_full (TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_LEFT,
TERMKEY_KEYMOD_CTRL, TERMKEY_KEYMOD_CTRL, 'd');
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_UP,
TERMO_KEYMOD_CTRL, TERMO_KEYMOD_CTRL, 'a');
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_DOWN,
TERMO_KEYMOD_CTRL, TERMO_KEYMOD_CTRL, 'b');
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_RIGHT,
TERMO_KEYMOD_CTRL, TERMO_KEYMOD_CTRL, 'c');
register_csi_ss3_full (TERMO_TYPE_KEYSYM, TERMO_SYM_LEFT,
TERMO_KEYMOD_CTRL, TERMO_KEYMOD_CTRL, 'd');
csi_handlers['^' - 0x40] = &handle_csi_caret;
@ -570,14 +570,14 @@ register_keys (void)
}
static void *
new_driver (termkey_t *tk, const char *term)
new_driver (termo_t *tk, const char *term)
{
(void) term;
if (!keyinfo_initialised && !register_keys ())
return NULL;
termkey_csi_t *csi = malloc (sizeof *csi);
termo_csi_t *csi = malloc (sizeof *csi);
if (!csi)
return NULL;
@ -588,13 +588,13 @@ new_driver (termkey_t *tk, const char *term)
static void
free_driver (void *info)
{
termkey_csi_t *csi = info;
termo_csi_t *csi = info;
free (csi);
}
static termkey_result_t
peekkey_csi (termkey_t *tk, termkey_csi_t *csi,
size_t introlen, termkey_key_t *key, int force, size_t *nbytep)
static termo_result_t
peekkey_csi (termo_t *tk, termo_csi_t *csi,
size_t introlen, termo_key_t *key, int force, size_t *nbytep)
{
(void) csi;
@ -603,16 +603,16 @@ peekkey_csi (termkey_t *tk, termkey_csi_t *csi,
long arg[16];
unsigned long cmd;
termkey_result_t ret = parse_csi (tk, introlen, &csi_len, arg, &args, &cmd);
if (ret == TERMKEY_RES_AGAIN)
termo_result_t ret = parse_csi (tk, introlen, &csi_len, arg, &args, &cmd);
if (ret == TERMO_RES_AGAIN)
{
if (!force)
return TERMKEY_RES_AGAIN;
return TERMO_RES_AGAIN;
(*tk->method.emit_codepoint) (tk, '[', key);
key->modifiers |= TERMKEY_KEYMOD_ALT;
key->modifiers |= TERMO_KEYMOD_ALT;
*nbytep = introlen;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
// Mouse in X10 encoding consumes the next 3 bytes also (or more with 1005)
@ -621,24 +621,24 @@ peekkey_csi (termkey_t *tk, termkey_csi_t *csi,
tk->buffstart += csi_len;
tk->buffcount -= csi_len;
termkey_result_t mouse_result =
termo_result_t mouse_result =
(*tk->method.peekkey_mouse) (tk, key, nbytep);
tk->buffstart -= csi_len;
tk->buffcount += csi_len;
if (mouse_result == TERMKEY_RES_KEY)
if (mouse_result == TERMO_RES_KEY)
*nbytep += csi_len;
return mouse_result;
}
termkey_result_t result = TERMKEY_RES_NONE;
termo_result_t result = TERMO_RES_NONE;
// We know from the logic above that cmd must be >= 0x40 and < 0x80
if (csi_handlers[(cmd & 0xff) - 0x40])
result = (*csi_handlers[(cmd & 0xff) - 0x40]) (tk, key, cmd, arg, args);
if (result == TERMKEY_RES_NONE)
if (result == TERMO_RES_NONE)
{
#ifdef DEBUG
switch (args)
@ -661,49 +661,49 @@ peekkey_csi (termkey_t *tk, termkey_csi_t *csi,
break;
}
#endif
key->type = TERMKEY_TYPE_UNKNOWN_CSI;
key->type = TERMO_TYPE_UNKNOWN_CSI;
key->code.number = cmd;
tk->hightide = csi_len - introlen;
*nbytep = introlen; // Do not yet eat the data bytes
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
*nbytep = csi_len;
return result;
}
static termkey_result_t
peekkey_ss3 (termkey_t *tk, termkey_csi_t *csi, size_t introlen,
termkey_key_t *key, int force, size_t *nbytep)
static termo_result_t
peekkey_ss3 (termo_t *tk, termo_csi_t *csi, size_t introlen,
termo_key_t *key, int force, size_t *nbytep)
{
(void) csi;
if (tk->buffcount < introlen + 1)
{
if (!force)
return TERMKEY_RES_AGAIN;
return TERMO_RES_AGAIN;
(*tk->method.emit_codepoint) (tk, 'O', key);
key->modifiers |= TERMKEY_KEYMOD_ALT;
key->modifiers |= TERMO_KEYMOD_ALT;
*nbytep = tk->buffcount;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
unsigned char cmd = CHARAT (introlen);
if (cmd < 0x40 || cmd >= 0x80)
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
key->type = csi_ss3s[cmd - 0x40].type;
key->code.sym = csi_ss3s[cmd - 0x40].sym;
key->modifiers = csi_ss3s[cmd - 0x40].modifier_set;
if (key->code.sym == TERMKEY_SYM_UNKNOWN)
if (key->code.sym == TERMO_SYM_UNKNOWN)
{
if (tk->flags & TERMKEY_FLAG_CONVERTKP && ss3_kpalts[cmd - 0x40])
if (tk->flags & TERMO_FLAG_CONVERTKP && ss3_kpalts[cmd - 0x40])
{
key->type = TERMKEY_TYPE_KEY;
key->type = TERMO_TYPE_KEY;
key->code.codepoint = ss3_kpalts[cmd - 0x40];
key->modifiers = 0;
@ -718,26 +718,26 @@ peekkey_ss3 (termkey_t *tk, termkey_csi_t *csi, size_t introlen,
}
}
if (key->code.sym == TERMKEY_SYM_UNKNOWN)
if (key->code.sym == TERMO_SYM_UNKNOWN)
{
#ifdef DEBUG
fprintf (stderr, "CSI: Unknown SS3 %c (0x%02x)\n", (char) cmd, cmd);
#endif
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
*nbytep = introlen + 1;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
static termkey_result_t
peekkey (termkey_t *tk, void *info,
termkey_key_t *key, int force, size_t *nbytep)
static termo_result_t
peekkey (termo_t *tk, void *info,
termo_key_t *key, int force, size_t *nbytep)
{
if (tk->buffcount == 0)
return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE;
return tk->is_closed ? TERMO_RES_EOF : TERMO_RES_NONE;
termkey_csi_t *csi = info;
termo_csi_t *csi = info;
// Now we're sure at least 1 byte is valid
unsigned char b0 = CHARAT (0);
@ -750,10 +750,10 @@ peekkey (termkey_t *tk, void *info,
return peekkey_ss3 (tk, csi, 1, key, force, nbytep);
if (b0 == 0x9b)
return peekkey_csi (tk, csi, 1, key, force, nbytep);
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
termkey_driver_t termkey_driver_csi =
termo_driver_t termo_driver_csi =
{
.name = "CSI",
.new_driver = new_driver,

View File

@ -1,8 +1,8 @@
// we want strdup()
#define _XOPEN_SOURCE 600
#include "termkey2.h"
#include "termkey2-internal.h"
#include "termo.h"
#include "termo-internal.h"
#ifdef HAVE_UNIBILIUM
# include <unibilium.h>
@ -53,7 +53,7 @@ trie_node_array_t;
typedef struct
{
termkey_t *tk;
termo_t *tk;
trie_node_t *root;
char *start_string;
@ -62,14 +62,14 @@ typedef struct
bool have_mouse;
char *set_mouse_string;
}
termkey_ti_t;
termo_ti_t;
static int funcname2keysym (const char *funcname, termkey_type_t *typep,
termkey_sym_t *symp, int *modmask, int *modsetp);
static int insert_seq (termkey_ti_t *ti, const char *seq, trie_node_t *node);
static int funcname2keysym (const char *funcname, termo_type_t *typep,
termo_sym_t *symp, int *modmask, int *modsetp);
static int insert_seq (termo_ti_t *ti, const char *seq, trie_node_t *node);
static trie_node_t *
new_node_key (termkey_type_t type, termkey_sym_t sym, int modmask, int modset)
new_node_key (termo_type_t type, termo_sym_t sym, int modmask, int modset)
{
trie_node_key_t *n = malloc (sizeof *n);
if (!n)
@ -176,7 +176,7 @@ compress_trie (struct trie_node *n)
}
static bool
load_terminfo (termkey_ti_t *ti, const char *term)
load_terminfo (termo_ti_t *ti, const char *term)
{
const char *mouse_report_string = NULL;
@ -212,15 +212,15 @@ load_terminfo (termkey_ti_t *ti, const char *term)
mouse_report_string = value;
else
{
termkey_type_t type;
termkey_sym_t sym;
termo_type_t type;
termo_sym_t sym;
int mask = 0;
int set = 0;
if (!funcname2keysym (name + 4, &type, &sym, &mask, &set))
continue;
if (sym == TERMKEY_SYM_NONE)
if (sym == TERMO_SYM_NONE)
continue;
node = new_node_key (type, sym, mask, set);
@ -262,7 +262,7 @@ load_terminfo (termkey_ti_t *ti, const char *term)
}
}
/* Take copies of these terminfo strings, in case we build multiple termkey
/* Take copies of these terminfo strings, in case we build multiple termo
* instances for multiple different termtypes, and it's different by the
* time we want to use it
*/
@ -292,9 +292,9 @@ load_terminfo (termkey_ti_t *ti, const char *term)
}
static void *
new_driver (termkey_t *tk, const char *term)
new_driver (termo_t *tk, const char *term)
{
termkey_ti_t *ti = calloc (1, sizeof *ti);
termo_ti_t *ti = calloc (1, sizeof *ti);
if (!ti)
return NULL;
@ -318,7 +318,7 @@ abort_free_ti:
}
static bool
write_string (termkey_t *tk, char *string)
write_string (termo_t *tk, char *string)
{
if (tk->fd == -1 || !isatty (tk->fd) || !string)
return true;
@ -340,7 +340,7 @@ write_string (termkey_t *tk, char *string)
}
static bool
set_mouse (termkey_ti_t *ti, bool enable)
set_mouse (termo_ti_t *ti, bool enable)
{
#ifdef HAVE_UNIBILIUM
unibi_var_t params[9] = { enable, 0, 0, 0, 0, 0, 0, 0, 0 };
@ -355,9 +355,9 @@ set_mouse (termkey_ti_t *ti, bool enable)
}
static int
start_driver (termkey_t *tk, void *info)
start_driver (termo_t *tk, void *info)
{
termkey_ti_t *ti = info;
termo_ti_t *ti = info;
// TODO: Don't start the mouse automatically, find a nice place to put
// a public function to be called by users.
// TODO: Try to autodetect rxvt and use its protocol instead of mode 1000
@ -368,9 +368,9 @@ start_driver (termkey_t *tk, void *info)
}
static int
stop_driver (termkey_t *tk, void *info)
stop_driver (termo_t *tk, void *info)
{
termkey_ti_t *ti = info;
termo_ti_t *ti = info;
if (ti->have_mouse && !set_mouse (ti, false))
return false;
return write_string (tk, ti->stop_string);
@ -379,7 +379,7 @@ stop_driver (termkey_t *tk, void *info)
static void
free_driver (void *info)
{
termkey_ti_t *ti = info;
termo_ti_t *ti = info;
free_trie (ti->root);
free (ti->set_mouse_string);
free (ti->start_string);
@ -389,14 +389,14 @@ free_driver (void *info)
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
static termkey_result_t
peekkey (termkey_t *tk, void *info,
termkey_key_t *key, int force, size_t *nbytep)
static termo_result_t
peekkey (termo_t *tk, void *info,
termo_key_t *key, int force, size_t *nbytep)
{
termkey_ti_t *ti = info;
termo_ti_t *ti = info;
if (tk->buffcount == 0)
return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE;
return tk->is_closed ? TERMO_RES_EOF : TERMO_RES_NONE;
trie_node_t *p = ti->root;
unsigned int pos = 0;
@ -415,20 +415,20 @@ peekkey (termkey_t *tk, void *info,
key->code.sym = nk->key.sym;
key->modifiers = nk->key.modifier_set;
*nbytep = pos;
return TERMKEY_RES_KEY;
return TERMO_RES_KEY;
}
else if (p->type == TYPE_MOUSE)
{
tk->buffstart += pos;
tk->buffcount -= pos;
termkey_result_t mouse_result =
termo_result_t mouse_result =
(*tk->method.peekkey_mouse) (tk, key, nbytep);
tk->buffstart -= pos;
tk->buffcount += pos;
if (mouse_result == TERMKEY_RES_KEY)
if (mouse_result == TERMO_RES_KEY)
*nbytep += pos;
return mouse_result;
@ -438,65 +438,65 @@ peekkey (termkey_t *tk, void *info,
// If p is not NULL then we hadn't walked off the end yet, so we have a
// partial match
if (p && !force)
return TERMKEY_RES_AGAIN;
return TERMO_RES_AGAIN;
return TERMKEY_RES_NONE;
return TERMO_RES_NONE;
}
static struct func
{
const char *funcname;
termkey_type_t type;
termkey_sym_t sym;
termo_type_t type;
termo_sym_t sym;
int mods;
}
funcs[] =
{
/* THIS LIST MUST REMAIN SORTED! */
{ "backspace", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BACKSPACE, 0 },
{ "begin", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BEGIN, 0 },
{ "beg", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_BEGIN, 0 },
{ "btab", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_TAB, TERMKEY_KEYMOD_SHIFT },
{ "cancel", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_CANCEL, 0 },
{ "clear", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_CLEAR, 0 },
{ "close", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_CLOSE, 0 },
{ "command", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_COMMAND, 0 },
{ "copy", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_COPY, 0 },
{ "dc", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DELETE, 0 },
{ "down", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_DOWN, 0 },
{ "end", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_END, 0 },
{ "enter", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_ENTER, 0 },
{ "exit", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_EXIT, 0 },
{ "find", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_FIND, 0 },
{ "help", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HELP, 0 },
{ "home", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_HOME, 0 },
{ "ic", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_INSERT, 0 },
{ "left", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_LEFT, 0 },
{ "mark", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_MARK, 0 },
{ "message", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_MESSAGE, 0 },
{ "mouse", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_NONE, 0 },
{ "move", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_MOVE, 0 },
{ "backspace", TERMO_TYPE_KEYSYM, TERMO_SYM_BACKSPACE, 0 },
{ "begin", TERMO_TYPE_KEYSYM, TERMO_SYM_BEGIN, 0 },
{ "beg", TERMO_TYPE_KEYSYM, TERMO_SYM_BEGIN, 0 },
{ "btab", TERMO_TYPE_KEYSYM, TERMO_SYM_TAB, TERMO_KEYMOD_SHIFT },
{ "cancel", TERMO_TYPE_KEYSYM, TERMO_SYM_CANCEL, 0 },
{ "clear", TERMO_TYPE_KEYSYM, TERMO_SYM_CLEAR, 0 },
{ "close", TERMO_TYPE_KEYSYM, TERMO_SYM_CLOSE, 0 },
{ "command", TERMO_TYPE_KEYSYM, TERMO_SYM_COMMAND, 0 },
{ "copy", TERMO_TYPE_KEYSYM, TERMO_SYM_COPY, 0 },
{ "dc", TERMO_TYPE_KEYSYM, TERMO_SYM_DELETE, 0 },
{ "down", TERMO_TYPE_KEYSYM, TERMO_SYM_DOWN, 0 },
{ "end", TERMO_TYPE_KEYSYM, TERMO_SYM_END, 0 },
{ "enter", TERMO_TYPE_KEYSYM, TERMO_SYM_ENTER, 0 },
{ "exit", TERMO_TYPE_KEYSYM, TERMO_SYM_EXIT, 0 },
{ "find", TERMO_TYPE_KEYSYM, TERMO_SYM_FIND, 0 },
{ "help", TERMO_TYPE_KEYSYM, TERMO_SYM_HELP, 0 },
{ "home", TERMO_TYPE_KEYSYM, TERMO_SYM_HOME, 0 },
{ "ic", TERMO_TYPE_KEYSYM, TERMO_SYM_INSERT, 0 },
{ "left", TERMO_TYPE_KEYSYM, TERMO_SYM_LEFT, 0 },
{ "mark", TERMO_TYPE_KEYSYM, TERMO_SYM_MARK, 0 },
{ "message", TERMO_TYPE_KEYSYM, TERMO_SYM_MESSAGE, 0 },
{ "mouse", TERMO_TYPE_KEYSYM, TERMO_SYM_NONE, 0 },
{ "move", TERMO_TYPE_KEYSYM, TERMO_SYM_MOVE, 0 },
// Not quite, but it's the best we can do
{ "next", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEDOWN, 0 },
{ "npage", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEDOWN, 0 },
{ "open", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_OPEN, 0 },
{ "options", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_OPTIONS, 0 },
{ "ppage", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEUP, 0 },
{ "next", TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEDOWN, 0 },
{ "npage", TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEDOWN, 0 },
{ "open", TERMO_TYPE_KEYSYM, TERMO_SYM_OPEN, 0 },
{ "options", TERMO_TYPE_KEYSYM, TERMO_SYM_OPTIONS, 0 },
{ "ppage", TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEUP, 0 },
// Not quite, but it's the best we can do
{ "previous", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PAGEUP, 0 },
{ "print", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_PRINT, 0 },
{ "redo", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_REDO, 0 },
{ "reference", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_REFERENCE, 0 },
{ "refresh", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_REFRESH, 0 },
{ "replace", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_REPLACE, 0 },
{ "restart", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RESTART, 0 },
{ "resume", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RESUME, 0 },
{ "right", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_RIGHT, 0 },
{ "save", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_SAVE, 0 },
{ "select", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_SELECT, 0 },
{ "suspend", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_SUSPEND, 0 },
{ "undo", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_UNDO, 0 },
{ "up", TERMKEY_TYPE_KEYSYM, TERMKEY_SYM_UP, 0 },
{ "previous", TERMO_TYPE_KEYSYM, TERMO_SYM_PAGEUP, 0 },
{ "print", TERMO_TYPE_KEYSYM, TERMO_SYM_PRINT, 0 },
{ "redo", TERMO_TYPE_KEYSYM, TERMO_SYM_REDO, 0 },
{ "reference", TERMO_TYPE_KEYSYM, TERMO_SYM_REFERENCE, 0 },
{ "refresh", TERMO_TYPE_KEYSYM, TERMO_SYM_REFRESH, 0 },
{ "replace", TERMO_TYPE_KEYSYM, TERMO_SYM_REPLACE, 0 },
{ "restart", TERMO_TYPE_KEYSYM, TERMO_SYM_RESTART, 0 },
{ "resume", TERMO_TYPE_KEYSYM, TERMO_SYM_RESUME, 0 },
{ "right", TERMO_TYPE_KEYSYM, TERMO_SYM_RIGHT, 0 },
{ "save", TERMO_TYPE_KEYSYM, TERMO_SYM_SAVE, 0 },
{ "select", TERMO_TYPE_KEYSYM, TERMO_SYM_SELECT, 0 },
{ "suspend", TERMO_TYPE_KEYSYM, TERMO_SYM_SUSPEND, 0 },
{ "undo", TERMO_TYPE_KEYSYM, TERMO_SYM_UNDO, 0 },
{ "up", TERMO_TYPE_KEYSYM, TERMO_SYM_UP, 0 },
{ NULL },
};
@ -508,7 +508,7 @@ func_compare (const void *key, const void *element)
static int
funcname2keysym (const char *funcname,
termkey_type_t *typep, termkey_sym_t *symp, int *modmaskp, int *modsetp)
termo_type_t *typep, termo_sym_t *symp, int *modmaskp, int *modsetp)
{
struct func *func = bsearch (funcname, funcs,
sizeof funcs / sizeof funcs[0], sizeof funcs[0], func_compare);
@ -523,7 +523,7 @@ funcname2keysym (const char *funcname,
if (funcname[0] == 'f' && isdigit (funcname[1]))
{
*typep = TERMKEY_TYPE_FUNCTION;
*typep = TERMO_TYPE_FUNCTION;
*symp = atoi (funcname + 1);
return 1;
}
@ -532,8 +532,8 @@ funcname2keysym (const char *funcname,
if (funcname[0] == 's' && funcname2keysym
(funcname + 1, typep, symp, modmaskp, modsetp))
{
*modmaskp |= TERMKEY_KEYMOD_SHIFT;
*modsetp |= TERMKEY_KEYMOD_SHIFT;
*modmaskp |= TERMO_KEYMOD_SHIFT;
*modsetp |= TERMO_KEYMOD_SHIFT;
return 1;
}
@ -546,7 +546,7 @@ funcname2keysym (const char *funcname,
}
static int
insert_seq (termkey_ti_t *ti, const char *seq, trie_node_t *node)
insert_seq (termo_ti_t *ti, const char *seq, trie_node_t *node)
{
int pos = 0;
trie_node_t *p = ti->root;
@ -603,7 +603,7 @@ insert_seq (termkey_ti_t *ti, const char *seq, trie_node_t *node)
return 1;
}
termkey_driver_t termkey_driver_ti =
termo_driver_t termo_driver_ti =
{
.name = "terminfo",
.new_driver = new_driver,

View File

@ -1,8 +0,0 @@
#ifndef TERMKEY2_CONFIG_H
#define TERMKEY2_CONFIG_H
#define TERMKEY_VERSION_MAJOR @project_VERSION_MAJOR@
#define TERMKEY_VERSION_MINOR @project_VERSION_MINOR@
#endif // ! TERMKEY2_CONFIG_H

View File

@ -1,277 +0,0 @@
#ifndef TERMKEY2_H
#define TERMKEY2_H
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include "termkey2-config.h"
#define TERMKEY_CHECK_VERSION \
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
};
typedef enum termkey_type termkey_type_t;
enum termkey_type
{
TERMKEY_TYPE_KEY,
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
};
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
};
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
};
enum
{
TERMKEY_KEYMOD_SHIFT = 1 << 0,
TERMKEY_KEYMOD_ALT = 1 << 1,
TERMKEY_KEYMOD_CTRL = 1 << 2
};
typedef struct termkey_key termkey_key_t;
struct termkey_key
{
termkey_type_t type;
union
{
uint32_t codepoint; /* TERMKEY_TYPE_KEY */
int number; /* TERMKEY_TYPE_FUNCTION */
termkey_sym_t sym; /* TERMKEY_TYPE_KEYSYM */
/* TERMKEY_TYPE_MODEREPORT */
/* opaque, see termkey_interpret_modereport() */
struct { char initial; int mode, value; } mode;
/* TERMKEY_TYPE_MOUSE */
/* opaque, see termkey_interpret_mouse() */
struct { uint16_t x, y, info; } mouse;
} code;
int modifiers;
/* The raw multibyte sequence for the key */
char multibyte[MB_LEN_MAX + 1];
};
typedef struct termkey termkey_t;
enum
{
/* 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
};
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);
termkey_t *termkey_new (int fd, const char *encoding, int flags);
termkey_t *termkey_new_abstract (const char *term,
const char *encoding, int flags);
void termkey_free (termkey_t *tk);
void termkey_destroy (termkey_t *tk);
int termkey_start (termkey_t *tk);
int termkey_stop (termkey_t *tk);
int termkey_is_started (termkey_t *tk);
int termkey_get_fd (termkey_t *tk);
int termkey_get_flags (termkey_t *tk);
void termkey_set_flags (termkey_t *tk, int newflags);
int termkey_get_waittime (termkey_t *tk);
void termkey_set_waittime (termkey_t *tk, int msec);
int termkey_get_canonflags (termkey_t *tk);
void termkey_set_canonflags (termkey_t *tk, int flags);
size_t termkey_get_buffer_size (termkey_t *tk);
int termkey_set_buffer_size (termkey_t *tk, size_t size);
size_t termkey_get_buffer_remaining (termkey_t *tk);
void termkey_canonicalise (termkey_t *tk, termkey_key_t *key);
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);
termkey_result_t termkey_advisereadable (termkey_t *tk);
size_t termkey_push_bytes (termkey_t *tk, const char *bytes, size_t len);
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);
termkey_sym_t termkey_keyname2sym (termkey_t *tk, const char *keyname);
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);
typedef enum termkey_format termkey_format_t;
enum termkey_format
{
/* 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
};
/* Some useful combinations */
#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)
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);
int termkey_keycmp (termkey_t *tk,
const termkey_key_t *key1, const termkey_key_t *key2);
#endif // ! TERMKEY2_H

8
termo-config.h.in Normal file
View File

@ -0,0 +1,8 @@
#ifndef TERMO_CONFIG_H
#define TERMO_CONFIG_H
#define TERMO_VERSION_MAJOR @project_VERSION_MAJOR@
#define TERMO_VERSION_MINOR @project_VERSION_MINOR@
#endif // ! TERMO_CONFIG_H

View File

@ -1,43 +1,43 @@
#ifndef TERMKEY2_INTERNAL_H
#define TERMKEY2_INTERNAL_H
#ifndef TERMO_INTERNAL_H
#define TERMO_INTERNAL_H
#include "termkey2.h"
#include "termo.h"
#include <stdint.h>
#include <termios.h>
#include <stdbool.h>
#include <iconv.h>
typedef struct termkey_driver termkey_driver_t;
struct termkey_driver
typedef struct termo_driver termo_driver_t;
struct termo_driver
{
const char *name;
void *(*new_driver) (termkey_t *tk, const char *term);
void *(*new_driver) (termo_t *tk, const char *term);
void (*free_driver) (void *info);
int (*start_driver) (termkey_t *tk, void *info);
int (*stop_driver) (termkey_t *tk, void *info);
termkey_result_t (*peekkey) (termkey_t *tk,
void *info, termkey_key_t *key, int force, size_t *nbytes);
int (*start_driver) (termo_t *tk, void *info);
int (*stop_driver) (termo_t *tk, void *info);
termo_result_t (*peekkey) (termo_t *tk,
void *info, termo_key_t *key, int force, size_t *nbytes);
};
typedef struct keyinfo keyinfo_t;
struct keyinfo
{
termkey_type_t type;
termkey_sym_t sym;
termo_type_t type;
termo_sym_t sym;
int modifier_mask;
int modifier_set;
};
typedef struct termkey_driver_node termkey_driver_node_t;
struct termkey_driver_node
typedef struct termo_driver_node termo_driver_node_t;
struct termo_driver_node
{
termkey_driver_t *driver;
termo_driver_t *driver;
void *info;
termkey_driver_node_t *next;
termo_driver_node_t *next;
};
struct termkey
struct termo
{
int fd;
int flags;
@ -49,7 +49,7 @@ struct termkey
size_t buffsize; // Total malloc'ed size
// Position beyond buffstart at which peekkey() should next start.
// Normally 0, but see also termkey_interpret_csi().
// Normally 0, but see also termo_interpret_csi().
size_t hightide;
struct termios restore_termios;
@ -66,24 +66,24 @@ struct termkey
keyinfo_t c0[32]; // There are 32 C0 codes
iconv_t to_utf32_conv;
iconv_t from_utf32_conv;
termkey_driver_node_t *drivers;
termo_driver_node_t *drivers;
// Now some "protected" methods for the driver to call but which we don't
// want exported as real symbols in the library
struct
{
void (*emit_codepoint) (termkey_t *tk,
uint32_t codepoint, termkey_key_t *key);
termkey_result_t (*peekkey_simple) (termkey_t *tk,
termkey_key_t *key, int force, size_t *nbytes);
termkey_result_t (*peekkey_mouse) (termkey_t *tk,
termkey_key_t *key, size_t *nbytes);
void (*emit_codepoint) (termo_t *tk,
uint32_t codepoint, termo_key_t *key);
termo_result_t (*peekkey_simple) (termo_t *tk,
termo_key_t *key, int force, size_t *nbytes);
termo_result_t (*peekkey_mouse) (termo_t *tk,
termo_key_t *key, size_t *nbytes);
}
method;
};
static inline void
termkey_key_get_linecol (const termkey_key_t *key, int *line, int *col)
termo_key_get_linecol (const termo_key_t *key, int *line, int *col)
{
if (col)
*col = key->code.mouse.x;
@ -93,7 +93,7 @@ termkey_key_get_linecol (const termkey_key_t *key, int *line, int *col)
}
static inline void
termkey_key_set_linecol (termkey_key_t *key, int line, int col)
termo_key_set_linecol (termo_key_t *key, int line, int col)
{
if (line > UINT16_MAX)
line = UINT16_MAX;
@ -105,8 +105,8 @@ termkey_key_set_linecol (termkey_key_t *key, int line, int col)
key->code.mouse.y = line;
}
extern termkey_driver_t termkey_driver_csi;
extern termkey_driver_t termkey_driver_ti;
extern termo_driver_t termo_driver_csi;
extern termo_driver_t termo_driver_ti;
#endif // ! TERMKEY2_INTERNAL_H
#endif // ! TERMO_INTERNAL_H

File diff suppressed because it is too large Load Diff

277
termo.h Normal file
View File

@ -0,0 +1,277 @@
#ifndef TERMO_H
#define TERMO_H
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include "termo-config.h"
#define TERMO_CHECK_VERSION \
termo_check_version (TERMO_VERSION_MAJOR, TERMO_VERSION_MINOR)
typedef enum termo_sym termo_sym_t;
enum termo_sym
{
TERMO_SYM_UNKNOWN = -1,
TERMO_SYM_NONE = 0,
/* Special names in C0 */
TERMO_SYM_BACKSPACE,
TERMO_SYM_TAB,
TERMO_SYM_ENTER,
TERMO_SYM_ESCAPE,
/* Special names in G0 */
TERMO_SYM_SPACE,
TERMO_SYM_DEL,
/* Special keys */
TERMO_SYM_UP,
TERMO_SYM_DOWN,
TERMO_SYM_LEFT,
TERMO_SYM_RIGHT,
TERMO_SYM_BEGIN,
TERMO_SYM_FIND,
TERMO_SYM_INSERT,
TERMO_SYM_DELETE,
TERMO_SYM_SELECT,
TERMO_SYM_PAGEUP,
TERMO_SYM_PAGEDOWN,
TERMO_SYM_HOME,
TERMO_SYM_END,
/* Special keys from terminfo */
TERMO_SYM_CANCEL,
TERMO_SYM_CLEAR,
TERMO_SYM_CLOSE,
TERMO_SYM_COMMAND,
TERMO_SYM_COPY,
TERMO_SYM_EXIT,
TERMO_SYM_HELP,
TERMO_SYM_MARK,
TERMO_SYM_MESSAGE,
TERMO_SYM_MOVE,
TERMO_SYM_OPEN,
TERMO_SYM_OPTIONS,
TERMO_SYM_PRINT,
TERMO_SYM_REDO,
TERMO_SYM_REFERENCE,
TERMO_SYM_REFRESH,
TERMO_SYM_REPLACE,
TERMO_SYM_RESTART,
TERMO_SYM_RESUME,
TERMO_SYM_SAVE,
TERMO_SYM_SUSPEND,
TERMO_SYM_UNDO,
/* Numeric keypad special keys */
TERMO_SYM_KP0,
TERMO_SYM_KP1,
TERMO_SYM_KP2,
TERMO_SYM_KP3,
TERMO_SYM_KP4,
TERMO_SYM_KP5,
TERMO_SYM_KP6,
TERMO_SYM_KP7,
TERMO_SYM_KP8,
TERMO_SYM_KP9,
TERMO_SYM_KPENTER,
TERMO_SYM_KPPLUS,
TERMO_SYM_KPMINUS,
TERMO_SYM_KPMULT,
TERMO_SYM_KPDIV,
TERMO_SYM_KPCOMMA,
TERMO_SYM_KPPERIOD,
TERMO_SYM_KPEQUALS,
TERMO_N_SYMS
};
typedef enum termo_type termo_type_t;
enum termo_type
{
TERMO_TYPE_KEY,
TERMO_TYPE_FUNCTION,
TERMO_TYPE_KEYSYM,
TERMO_TYPE_MOUSE,
TERMO_TYPE_POSITION,
TERMO_TYPE_MODEREPORT,
/* add other recognised types here */
TERMO_TYPE_UNKNOWN_CSI = -1
};
typedef enum termo_result termo_result_t;
enum termo_result
{
TERMO_RES_NONE,
TERMO_RES_KEY,
TERMO_RES_EOF,
TERMO_RES_AGAIN,
TERMO_RES_ERROR
};
typedef enum termo_mouse_event termo_mouse_event_t;
enum termo_mouse_event
{
TERMO_MOUSE_UNKNOWN,
TERMO_MOUSE_PRESS,
TERMO_MOUSE_DRAG,
TERMO_MOUSE_RELEASE
};
enum
{
TERMO_KEYMOD_SHIFT = 1 << 0,
TERMO_KEYMOD_ALT = 1 << 1,
TERMO_KEYMOD_CTRL = 1 << 2
};
typedef struct termo_key termo_key_t;
struct termo_key
{
termo_type_t type;
union
{
uint32_t codepoint; /* TERMO_TYPE_KEY */
int number; /* TERMO_TYPE_FUNCTION */
termo_sym_t sym; /* TERMO_TYPE_KEYSYM */
/* TERMO_TYPE_MODEREPORT */
/* opaque, see termo_interpret_modereport() */
struct { char initial; int mode, value; } mode;
/* TERMO_TYPE_MOUSE */
/* opaque, see termo_interpret_mouse() */
struct { uint16_t x, y, info; } mouse;
} code;
int modifiers;
/* The raw multibyte sequence for the key */
char multibyte[MB_LEN_MAX + 1];
};
typedef struct termo termo_t;
enum
{
/* Do not interpret C0//DEL codes if possible */
TERMO_FLAG_NOINTERPRET = 1 << 0,
/* Convert KP codes to regular keypresses */
TERMO_FLAG_CONVERTKP = 1 << 1,
/* Don't try to decode the input characters */
TERMO_FLAG_RAW = 1 << 2,
/* Do not make initial termios calls on construction */
TERMO_FLAG_NOTERMIOS = 1 << 4,
/* Sets TERMO_CANON_SPACESYMBOL */
TERMO_FLAG_SPACESYMBOL = 1 << 5,
/* Allow Ctrl-C to be read as normal, disabling SIGINT */
TERMO_FLAG_CTRLC = 1 << 6,
/* Return ERROR on signal (EINTR) rather than retry */
TERMO_FLAG_EINTR = 1 << 7
};
enum
{
TERMO_CANON_SPACESYMBOL = 1 << 0, /* Space is symbolic rather than Unicode */
TERMO_CANON_DELBS = 1 << 1 /* Del is converted to Backspace */
};
void termo_check_version (int major, int minor);
termo_t *termo_new (int fd, const char *encoding, int flags);
termo_t *termo_new_abstract (const char *term,
const char *encoding, int flags);
void termo_free (termo_t *tk);
void termo_destroy (termo_t *tk);
int termo_start (termo_t *tk);
int termo_stop (termo_t *tk);
int termo_is_started (termo_t *tk);
int termo_get_fd (termo_t *tk);
int termo_get_flags (termo_t *tk);
void termo_set_flags (termo_t *tk, int newflags);
int termo_get_waittime (termo_t *tk);
void termo_set_waittime (termo_t *tk, int msec);
int termo_get_canonflags (termo_t *tk);
void termo_set_canonflags (termo_t *tk, int flags);
size_t termo_get_buffer_size (termo_t *tk);
int termo_set_buffer_size (termo_t *tk, size_t size);
size_t termo_get_buffer_remaining (termo_t *tk);
void termo_canonicalise (termo_t *tk, termo_key_t *key);
termo_result_t termo_getkey (termo_t *tk, termo_key_t *key);
termo_result_t termo_getkey_force (termo_t *tk, termo_key_t *key);
termo_result_t termo_waitkey (termo_t *tk, termo_key_t *key);
termo_result_t termo_advisereadable (termo_t *tk);
size_t termo_push_bytes (termo_t *tk, const char *bytes, size_t len);
termo_sym_t termo_register_keyname (termo_t *tk,
termo_sym_t sym, const char *name);
const char *termo_get_keyname (termo_t *tk, termo_sym_t sym);
const char *termo_lookup_keyname (termo_t *tk,
const char *str, termo_sym_t *sym);
termo_sym_t termo_keyname2sym (termo_t *tk, const char *keyname);
termo_result_t termo_interpret_mouse (termo_t *tk,
const termo_key_t *key, termo_mouse_event_t *event,
int *button, int *line, int *col);
termo_result_t termo_interpret_position (termo_t *tk,
const termo_key_t *key, int *line, int *col);
termo_result_t termo_interpret_modereport (termo_t *tk,
const termo_key_t *key, int *initial, int *mode, int *value);
termo_result_t termo_interpret_csi (termo_t *tk,
const termo_key_t *key, long args[], size_t *nargs, unsigned long *cmd);
typedef enum termo_format termo_format_t;
enum termo_format
{
/* Shift-... instead of S-... */
TERMO_FORMAT_LONGMOD = 1 << 0,
/* ^X instead of C-X */
TERMO_FORMAT_CARETCTRL = 1 << 1,
/* Meta- or M- instead of Alt- or A- */
TERMO_FORMAT_ALTISMETA = 1 << 2,
/* Wrap special keys in brackets like <Escape> */
TERMO_FORMAT_WRAPBRACKET = 1 << 3,
/* M Foo instead of M-Foo */
TERMO_FORMAT_SPACEMOD = 1 << 4,
/* meta or m instead of Meta or M */
TERMO_FORMAT_LOWERMOD = 1 << 5,
/* page down instead of PageDown */
TERMO_FORMAT_LOWERSPACE = 1 << 6,
/* Include mouse position if relevant; @ col,line */
TERMO_FORMAT_MOUSE_POS = 1 << 8
};
/* Some useful combinations */
#define TERMO_FORMAT_VIM (termo_format_t) \
(TERMO_FORMAT_ALTISMETA | TERMO_FORMAT_WRAPBRACKET)
#define TERMO_FORMAT_URWID (termo_format_t) \
(TERMO_FORMAT_LONGMOD | TERMO_FORMAT_ALTISMETA | \
TERMO_FORMAT_LOWERMOD | TERMO_FORMAT_SPACEMOD | \
TERMO_FORMAT_LOWERSPACE)
size_t termo_strfkey (termo_t *tk, char *buffer, size_t len,
termo_key_t *key, termo_format_t format);
const char *termo_strpkey (termo_t *tk, const char *str,
termo_key_t *key, termo_format_t format);
int termo_keycmp (termo_t *tk,
const termo_key_t *key1, const termo_key_t *key2);
#endif // ! TERMO_H