Hello community, here is the log from the commit of package libtermkey for openSUSE:Factory checked in at 2018-05-29 16:50:22 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libtermkey (Old) and /work/SRC/openSUSE:Factory/.libtermkey.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libtermkey" Tue May 29 16:50:22 2018 rev:2 rq:611658 version:0.20 Changes: -------- --- /work/SRC/openSUSE:Factory/libtermkey/libtermkey.changes 2016-01-28 17:22:41.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.libtermkey.new/libtermkey.changes 2018-05-29 16:50:45.435168753 +0200 @@ -1,0 +2,8 @@ +Wed May 23 08:16:07 UTC 2018 - [email protected] + +- Bump to version 0.20: + * added parsing of DCS and OSC control strings + * fixed handling of Ctrl-Space, bugfix for keypad mode switching, + endian fix for unicode keys (thanks jamessan) + +------------------------------------------------------------------- Old: ---- libtermkey-0.18.tar.gz New: ---- libtermkey-0.20.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libtermkey.spec ++++++ --- /var/tmp/diff_new_pack.qbYxbE/_old 2018-05-29 16:50:46.775119449 +0200 +++ /var/tmp/diff_new_pack.qbYxbE/_new 2018-05-29 16:50:46.775119449 +0200 @@ -1,7 +1,7 @@ # # spec file for package libtermkey # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %define soname 1 Name: libtermkey -Version: 0.18 +Version: 0.20 Release: 0 Summary: Library for easy processing of keyboard entry from terminal-based programs License: MIT @@ -103,3 +103,4 @@ %{_mandir}/man3/termkey*.3%{ext_man} %{_mandir}/man7/termkey.* +%changelog ++++++ libtermkey-0.18.tar.gz -> libtermkey-0.20.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/Makefile new/libtermkey-0.20/Makefile --- old/libtermkey-0.18/Makefile 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/Makefile 2017-03-30 15:17:09.000000000 +0200 @@ -49,11 +49,11 @@ TESTFILES=$(TESTSOURCES:.c=.t) VERSION_MAJOR=0 -VERSION_MINOR=18 +VERSION_MINOR=20 -VERSION_CURRENT=13 +VERSION_CURRENT=15 VERSION_REVISION=0 -VERSION_AGE=12 +VERSION_AGE=14 PREFIX=/usr/local LIBDIR=$(PREFIX)/lib diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/driver-csi.c new/libtermkey-0.20/driver-csi.c --- old/libtermkey-0.18/driver-csi.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/driver-csi.c 2017-03-30 15:17:09.000000000 +0200 @@ -11,6 +11,8 @@ typedef struct { TermKey *tk; + int saved_string_id; + char *saved_string; } TermKeyCsi; typedef TermKeyResult CsiHandler(TermKey *tk, TermKeyKey *key, int cmd, long *arg, int args); @@ -508,6 +510,8 @@ return NULL; csi->tk = tk; + csi->saved_string_id = 0; + csi->saved_string = NULL; return csi; } @@ -516,6 +520,9 @@ { TermKeyCsi *csi = info; + if(csi->saved_string) + free(csi->saved_string); + free(csi); } @@ -637,6 +644,52 @@ return TERMKEY_RES_KEY; } +static TermKeyResult peekkey_ctrlstring(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) +{ + size_t str_end = introlen; + + while(str_end < tk->buffcount) { + if(CHARAT(str_end) == 0x9c) // ST + break; + if(CHARAT(str_end) == 0x1b && + (str_end + 1) < tk->buffcount && + CHARAT(str_end+1) == 0x5c) // ESC-prefixed ST + break; + + str_end++; + } + + if(str_end >= tk->buffcount) + return TERMKEY_RES_AGAIN; + +#ifdef DEBUG + fprintf(stderr, "Found a control string: %*s", + str_end - introlen, tk->buffer + tk->buffstart + introlen); +#endif + + *nbytep = str_end + 1; + if(CHARAT(str_end) == 0x1b) + (*nbytep)++; + + if(csi->saved_string) + free(csi->saved_string); + + size_t len = str_end - introlen; + + csi->saved_string_id++; + csi->saved_string = malloc(len + 1); + + strncpy(csi->saved_string, (char *)tk->buffer + tk->buffstart + introlen, len); + csi->saved_string[len] = 0; + + key->type = (CHARAT(introlen-1) & 0x1f) == 0x10 ? + TERMKEY_TYPE_DCS : TERMKEY_TYPE_OSC; + key->code.number = csi->saved_string_id; + key->modifiers = 0; + + return TERMKEY_RES_KEY; +} + static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) { if(tk->buffcount == 0) @@ -644,23 +697,37 @@ TermKeyCsi *csi = info; - // Now we're sure at least 1 byte is valid - unsigned char b0 = CHARAT(0); + switch(CHARAT(0)) { + case 0x1b: + if(tk->buffcount < 2) + return TERMKEY_RES_NONE; - if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == '[') { - return peekkey_csi(tk, csi, 2, key, force, nbytep); - } - else if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == 'O') { - return peekkey_ss3(tk, csi, 2, key, force, nbytep); - } - else if(b0 == 0x8f) { - return peekkey_ss3(tk, csi, 1, key, force, nbytep); - } - else if(b0 == 0x9b) { - return peekkey_csi(tk, csi, 1, key, force, nbytep); + switch(CHARAT(1)) { + case 0x4f: // ESC-prefixed SS3 + return peekkey_ss3(tk, csi, 2, key, force, nbytep); + + case 0x50: // ESC-prefixed DCS + case 0x5d: // ESC-prefixed OSC + return peekkey_ctrlstring(tk, csi, 2, key, force, nbytep); + + case 0x5b: // ESC-prefixed CSI + return peekkey_csi(tk, csi, 2, key, force, nbytep); + } + + return TERMKEY_RES_NONE; + + case 0x8f: // SS3 + return peekkey_ss3(tk, csi, 1, key, force, nbytep); + + case 0x90: // DCS + case 0x9d: // OSC + return peekkey_ctrlstring(tk, csi, 1, key, force, nbytep); + + case 0x9b: // CSI + return peekkey_csi(tk, csi, 1, key, force, nbytep); } - else - return TERMKEY_RES_NONE; + + return TERMKEY_RES_NONE; } struct TermKeyDriver termkey_driver_csi = { @@ -671,3 +738,27 @@ .peekkey = peekkey, }; + +TermKeyResult termkey_interpret_string(TermKey *tk, const TermKeyKey *key, const char **strp) +{ + struct TermKeyDriverNode *p; + for(p = tk->drivers; p; p = p->next) + if(p->driver == &termkey_driver_csi) + break; + + if(!p) + return TERMKEY_RES_NONE; + + if(key->type != TERMKEY_TYPE_DCS && + key->type != TERMKEY_TYPE_OSC) + return TERMKEY_RES_NONE; + + TermKeyCsi *csi = p->info; + + if(csi->saved_string_id != key->code.number) + return TERMKEY_RES_NONE; + + *strp = csi->saved_string; + + return TERMKEY_RES_KEY; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/driver-null.c new/libtermkey-0.20/driver-null.c --- old/libtermkey-0.18/driver-null.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/driver-null.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ -#include "termkey.h" -#include "termkey-internal.h" - -static void *new_driver(termkey_t *tk, const char *term) -{ - return NULL; -} - -static int start_driver(termkey_t *tk, void *info) -{ - // This is optional - return 1; -} - -static int stop_driver(termkey_t *tk, void *info) -{ - // This is optional - return 1; -} - -static void free_driver(void *info) -{ -} - -static termkey_result getkey(termkey_t *tk, void *info, termkey_key *key, int force) -{ - return TERMKEY_RES_NONE; -} - -struct termkey_driver termkey_driver_null = { - .new_driver = new_driver, - .free_driver = free_driver, - - .start_driver = start_driver, - .stop_driver = stop_driver, - - .getkey = getkey, -}; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/driver-ti.c new/libtermkey-0.20/driver-ti.c --- old/libtermkey-0.18/driver-ti.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/driver-ti.c 2017-03-30 15:17:09.000000000 +0200 @@ -51,6 +51,12 @@ typedef struct { TermKey *tk; +#ifdef HAVE_UNIBILIUM + unibi_term *unibi; /* only valid until first 'start' call */ +#else + char *term; /* only valid until first 'start' call */ +#endif + struct trie_node *root; char *start_string; @@ -163,23 +169,27 @@ return n; } -static int load_terminfo(TermKeyTI *ti, const char *term) +static int load_terminfo(TermKeyTI *ti) { int i; #ifdef HAVE_UNIBILIUM - unibi_term *unibi = unibi_from_term(term); - if(!unibi) - return 0; + unibi_term *unibi = ti->unibi; #else - int err; + { + int err; - /* Have to cast away the const. But it's OK - we know terminfo won't really - * modify term */ - if(setupterm((char*)term, 1, &err) != OK) - return 0; + /* Have to cast away the const. But it's OK - we know terminfo won't really + * modify term */ + if(setupterm((char*)ti->term, 1, &err) != OK) + return 0; + } #endif + ti->root = new_node_arr(0, 0xff); + if(!ti->root) + return 0; + #ifdef HAVE_UNIBILIUM for(i = unibi_string_begin_+1; i < unibi_string_end_; i++) #else @@ -200,6 +210,10 @@ #else const char *value = tigetstr(strnames[i]); #endif + + if(ti->tk->ti_getstr_hook) + value = (ti->tk->ti_getstr_hook)(name, value, ti->tk->ti_getstr_hook_data); + if(!value || value == (char*)-1) continue; @@ -239,7 +253,7 @@ * time we want to use it */ #ifdef HAVE_UNIBILIUM - const char *keypad_xmit = unibi_get_str(unibi, unibi_pkey_xmit); + const char *keypad_xmit = unibi_get_str(unibi, unibi_keypad_xmit); #endif if(keypad_xmit) @@ -248,7 +262,7 @@ ti->start_string = NULL; #ifdef HAVE_UNIBILIUM - const char *keypad_local = unibi_get_str(unibi, unibi_pkey_local); + const char *keypad_local = unibi_get_str(unibi, unibi_keypad_local); #endif if(keypad_local) @@ -258,8 +272,12 @@ #ifdef HAVE_UNIBILIUM unibi_destroy(unibi); +#else + free(ti->term); #endif + ti->root = compress_trie(ti->root); + return 1; } @@ -270,22 +288,28 @@ return NULL; ti->tk = tk; + ti->root = NULL; - ti->root = new_node_arr(0, 0xff); - if(!ti->root) - goto abort_free_ti; +#ifdef HAVE_UNIBILIUM + ti->unibi = unibi_from_term(term); + if(!ti->unibi) + goto abort_free; +#else + { + int err; - if(!load_terminfo(ti, term)) - goto abort_free_trie; + /* Have to cast away the const. But it's OK - we know terminfo won't really + * modify term */ + if(setupterm((char*)term, 1, &err) != OK) + goto abort_free; - ti->root = compress_trie(ti->root); + ti->term = strdup(term); + } +#endif return ti; -abort_free_trie: - free_trie(ti->root); - -abort_free_ti: +abort_free: free(ti); return NULL; @@ -295,9 +319,14 @@ { TermKeyTI *ti = info; struct stat statbuf; - char *start_string = ti->start_string; + char *start_string; size_t len; + if(!ti->root) + load_terminfo(ti); + + start_string = ti->start_string; + if(tk->fd == -1 || !start_string) return 1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/man/termkey.7 new/libtermkey-0.20/man/termkey.7 --- old/libtermkey-0.18/man/termkey.7 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/man/termkey.7 2017-03-30 15:17:09.000000000 +0200 @@ -55,6 +55,12 @@ .B TERMKEY_TYPE_MODEREPORT an ANSI or DEC mode value report. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_modereport\fP(3) may be used to interpret it. .TP +.B TERMKEY_TYPE_DCS +a DCS sequence including its terminator. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_string\fP(3) may be used to interpret it. +.TP +.B TERMKEY_TYPE_OSC +a OSC sequence including its terminator. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_string\fP(3) may be used to interpret it. +.TP .B TERMKEY_TYPE_UNKNOWN_CSI an unrecognised CSI sequence. The \fIcode\fP structure should be considered opaque; \fBtermkey_interpret_csi\fP(3) may be used to interpret it. .PP @@ -103,6 +109,9 @@ .TP .B TERMKEY_FLAG_EINTR Without this flag, IO operations are retried when interrupted by a signal (\fBEINTR\fP). With this flag the \fBTERMKEY_RES_ERROR\fP result is returned instead. +.TP +.B TERMKEY_FLAG_NOSTART +This flag is only meaningful to the constructor functions \fBtermkey_new\fP(3) and \fBtermkey_new_abstract\fP(3). If set, the constructor will not call \fBtermkey_start\fP(3) as part of the construction process. The user must call that at some future time before the instance will be usable. .PP The following canonicalisation flags are recognised. .TP @@ -137,6 +146,8 @@ The \fBTERMKEY_TYPE_POSITION\fP event type indicates a cursor position report. This is typically sent by a terminal in response to the Report Cursor Position command (\f(CWCSI ? 6 n\fP). The event bytes are opaque, but can be obtained by calling \fBtermkey_interpret_position\fP(3) passing the event structure and pointers to integers to store the result in. Note that only a DEC CPR sequence (\f(CWCSI ? R\fP) is recognised, and not the non-DEC prefixed \f(CWCSI R\fP because the latter could be interpreted as the \f(CWF3\fP function key instead. .SS Mode Reports The \fBTERMKEY_TYPE_MODEREPORT\fP event type indicates an ANSI or DEC mode report. This is typically sent by a terminal in response to the Request Mode command (\f(CWCSI $p\fP or \f(CWCSI ? $p\fP). The event bytes are opaque, but can be obtained by calling \fBtermkey_interpret_modereport\fP(3) passing the event structure and pointers to integers to store the result in. +.SS Control Strings +The \fBTERMKEY_TYPE_DCS\fP and \fBTERMKEY_TYPE_OSC\fP event types indicate a DCS or OSC control string. These are typically sent by the terminal in response of similar kinds of strings being sent as queries by the application. The event bytes are opaque, but the body of the string itself can be obtained by calling \fBtermkey_interpret_string\fP(3) immediately after this event is received. The underlying \fBtermkey\fP instance itself can only store one pending string, so the application should be sure to call this function in a timely manner soon after the event is received; at the very least, before calling any other functions that will insert bytes into or remove key events from the instance. .SS Unrecognised CSIs The \fBTERMKEY_TYPE_UNKNOWN_CSI\fP event type indicates a CSI sequence that the \fBtermkey\fP does not recognise. It will have been extracted from the stream, but is available to the application to inspect by calling \fBtermkey_interpret_csi\fP(3). It is important that if the application wishes to inspect this sequence it is done immediately, before any other IO operations on the \fBtermkey\fP instance (specifically, before calling \fBtermkey_waitkey\fP() or \fBtermkey_getkey\fP() again), otherwise the buffer space consumed by the sequence will be overwritten. Other types of key event do not suffer this limitation as the \fBTermKeyKey\fP structure is sufficient to contain all the information required. .SH "SEE ALSO" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/man/termkey_interpret_string.3 new/libtermkey-0.20/man/termkey_interpret_string.3 --- old/libtermkey-0.18/man/termkey_interpret_string.3 1970-01-01 01:00:00.000000000 +0100 +++ new/libtermkey-0.20/man/termkey_interpret_string.3 2017-03-30 15:17:09.000000000 +0200 @@ -0,0 +1,24 @@ +.TH TERMKEY_INTERPRET_STRING 3 +.SH NAME +termkey_interpret_string \- fetch stored control string +.SH SYNOPSIS +.nf +.B #include <termkey.h> +.sp +.BI "TermKeyResult termkey_interpret_string(TermKey *" tk ", const TermKeyKey *" key ", " +.BI " const char **" strp ); +.fi +.sp +Link with \fI-ltermkey\fP. +.SH DESCRIPTION +\fBtermkey_interpret_string\fP() fetches the string stored in the \fBTermKey\fP instance from the most recently received \fBTERMKEY_TYPE_DCS\fP or \fBTERMKEY_TYPE_OSC\fP event. Note that it is important to call this function as soon as possible after obtaining a one of these string key event; specifically, before calling \fBtermkey_getkey\fP() or \fBtermkey_waitkey\fP() again, as a subsequent call will overwrite the buffer space currently containing this string. +.PP +The string pointer whose address is given by \fIstrp\fP will be set to point at the actual stored string in the instance. The caller is free to read this string (which will be correctly NUL-terminated), but should not modify it. It is not necessary to \fBfree\fP() the pointer; the containing \fBTermKey\fP instance will do that. +.SH "RETURN VALUE" +If passed the most recent \fIkey\fP event of the type \fBTERMKEY_TYPE_DCS\fP or \fBTERMKEY_TYPE_OSC\fP, this function will return \fBTERMKEY_RES_KEY\fP and will affect the variables whose pointers were passed in, as described above. +.PP +For other event types, or stale events, it will return \fBTERMKEY_RES_NONE\fP, and its effects on any variables whose pointers were passed in are undefined. +.SH "SEE ALSO" +.BR termkey_waitkey (3), +.BR termkey_getkey (3), +.BR termkey (7) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/man/termkey_new.3 new/libtermkey-0.20/man/termkey_new.3 --- old/libtermkey-0.18/man/termkey_new.3 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/man/termkey_new.3 2017-03-30 15:17:09.000000000 +0200 @@ -24,6 +24,8 @@ aware or not, and sets either the \fBTERMKEY_FLAG_UTF8\fP or \fBTERMKEY_FLAG_RAW\fP flag. One of these two bits will always be in effect. The current flags in effect can be obtained by \fBtermkey_get_flags\fP(3). .PP If a file handle is provided, the terminfo driver may send a string to initialise or set the state of the terminal before \fBtermkey_new\fP() returns. This will not be done if no file handle is provided, or if the file handle is a pipe (\fBS_ISFIFO\fP()). In this case it will be the caller's responsibility to ensure the terminal is in the correct mode. Once initialised, the terminal can be stopped by \fBtermkey_stop\fP(3), and started again by \fBtermkey_start\fP(3). +.PP +This behaviour is modified by the \fBTERMKEY_FLAG_NOSTART\fP flag. If passed in the \fIflags\fP argument then the instance will not be started yet by the constructor; the caller must invoke \fBtermkey_start\fP() at some future point before the instance will be usable. .SH VERSION CHECK MACRO Before calling any functions in the \fBtermkey\fP library, an application should use the \fBTERMKEY_CHECK_VERSION\fP macro to check that the loaded version of the library is compatible with the version it was compiled against. This should be done early on, ideally just after entering its \fBmain\fP() function. .SH "RETURN VALUE" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/man/termkey_waitkey.3 new/libtermkey-0.20/man/termkey_waitkey.3 --- old/libtermkey-0.18/man/termkey_waitkey.3 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/man/termkey_waitkey.3 2017-03-30 15:17:09.000000000 +0200 @@ -79,6 +79,11 @@ exit(1); } + if(termkey_get_flags(tk) & TERMKEY_FLAG_UTF8) + printf("Termkey in UTF-8 mode\\n"); + else if(termkey_get_flags(tk) & TERMKEY_FLAG_RAW) + printf("Termkey in RAW mode\\n"); + TermKeyResult ret; TermKeyKey key; @@ -114,7 +119,7 @@ printf("Unrecognised CSI %c %ld;%ld %c%c\\n", (char)(command >> 8), args[0], args[1], (char)(command >> 16), (char)command); } else { - printf("%s\\n", buffer); + printf("Key %s\\n", buffer); } if(key.type == TERMKEY_TYPE_UNICODE && diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/02getkey.c new/libtermkey-0.20/t/02getkey.c --- old/libtermkey-0.18/t/02getkey.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/t/02getkey.c 2017-03-30 15:17:09.000000000 +0200 @@ -6,7 +6,7 @@ TermKey *tk; TermKeyKey key; - plan_tests(31); + plan_tests(35); tk = termkey_new_abstract("vt100", 0); @@ -69,6 +69,14 @@ is_int(key.code.sym, TERMKEY_SYM_ESCAPE, "key.code.sym after Ctrl-Escape"); is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers after Ctrl-Escape"); + termkey_push_bytes(tk, "\0", 1); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after Ctrl-Space"); + + is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type after Ctrl-Space"); + is_int(key.code.codepoint, ' ', "key.code.codepoint after Ctrl-Space"); + is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers after Ctrl-Space"); + termkey_destroy(tk); return exit_status(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/05read.c new/libtermkey-0.20/t/05read.c --- old/libtermkey-0.18/t/05read.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/t/05read.c 2017-03-30 15:17:09.000000000 +0200 @@ -1,5 +1,6 @@ #include <stdio.h> #include <errno.h> +#include <unistd.h> #include "../termkey.h" #include "taplib.h" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/38csi.c new/libtermkey-0.20/t/38csi.c --- old/libtermkey-0.18/t/38csi.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libtermkey-0.20/t/38csi.c 2017-03-30 15:17:09.000000000 +0200 @@ -0,0 +1,46 @@ +#include "../termkey.h" +#include "taplib.h" + +int main(int argc, char *argv[]) +{ + TermKey *tk; + TermKeyKey key; + long args[16]; + size_t nargs = 16; + unsigned long command; + + plan_tests(15); + + tk = termkey_new_abstract("vt100", 0); + + termkey_push_bytes(tk, "\e[5;25v", 7); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI v"); + + is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); + + is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); + + is_int(nargs, 2, "nargs for unknown CSI"); + is_int(args[0], 5, "args[0] for unknown CSI"); + is_int(args[1], 25, "args[1] for unknown CSI"); + is_int(command, 'v', "command for unknown CSI"); + + termkey_push_bytes(tk, "\e[?w", 4); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? w"); + is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); + is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); + is_int(command, '?'<<8 | 'w', "command for unknown CSI"); + + termkey_push_bytes(tk, "\e[?$x", 5); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? $x"); + is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); + is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); + is_int(command, '$'<<16 | '?'<<8 | 'x', "command for unknown CSI"); + + termkey_destroy(tk); + + return exit_status(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/39csi.c new/libtermkey-0.20/t/39csi.c --- old/libtermkey-0.18/t/39csi.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/t/39csi.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,46 +0,0 @@ -#include "../termkey.h" -#include "taplib.h" - -int main(int argc, char *argv[]) -{ - TermKey *tk; - TermKeyKey key; - long args[16]; - size_t nargs = 16; - unsigned long command; - - plan_tests(15); - - tk = termkey_new_abstract("vt100", 0); - - termkey_push_bytes(tk, "\e[5;25v", 7); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI v"); - - is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); - - is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); - - is_int(nargs, 2, "nargs for unknown CSI"); - is_int(args[0], 5, "args[0] for unknown CSI"); - is_int(args[1], 25, "args[1] for unknown CSI"); - is_int(command, 'v', "command for unknown CSI"); - - termkey_push_bytes(tk, "\e[?w", 4); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? w"); - is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); - is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); - is_int(command, '?'<<8 | 'w', "command for unknown CSI"); - - termkey_push_bytes(tk, "\e[?$x", 5); - - is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? $x"); - is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); - is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); - is_int(command, '$'<<16 | '?'<<8 | 'x', "command for unknown CSI"); - - termkey_destroy(tk); - - return exit_status(); -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/39dcs.c new/libtermkey-0.20/t/39dcs.c --- old/libtermkey-0.18/t/39dcs.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libtermkey-0.20/t/39dcs.c 2017-03-30 15:17:09.000000000 +0200 @@ -0,0 +1,67 @@ +#include "../termkey.h" +#include "taplib.h" + +int main(int argc, char *argv[]) +{ + TermKey *tk; + TermKeyKey key; + const char *str; + + plan_tests(23); + + tk = termkey_new_abstract("xterm", 0); + + // 7bit DCS + termkey_push_bytes(tk, "\eP1$r1 q\e\\", 10); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for DCS"); + + is_int(key.type, TERMKEY_TYPE_DCS, "key.type for DCS"); + is_int(key.modifiers, 0, "key.modifiers for DCS"); + + is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); + is_str(str, "1$r1 q", "termkey_interpret_string() yields correct string"); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); + + // 8bit DCS + termkey_push_bytes(tk, "\x90""1$r2 q""\x9c", 8); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for DCS"); + + is_int(key.type, TERMKEY_TYPE_DCS, "key.type for DCS"); + is_int(key.modifiers, 0, "key.modifiers for DCS"); + + is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); + is_str(str, "1$r2 q", "termkey_interpret_string() yields correct string"); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); + + // 7bit OSC + termkey_push_bytes(tk, "\e]15;abc\e\\", 10); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for OSC"); + + is_int(key.type, TERMKEY_TYPE_OSC, "key.type for OSC"); + is_int(key.modifiers, 0, "key.modifiers for OSC"); + + is_int(termkey_interpret_string(tk, &key, &str), TERMKEY_RES_KEY, "termkey_interpret_string() gives string"); + is_str(str, "15;abc", "termkey_interpret_string() yields correct string"); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey again yields RES_NONE"); + + // False alarm + termkey_push_bytes(tk, "\eP", 2); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN for false alarm"); + + is_int(termkey_getkey_force(tk, &key), TERMKEY_RES_KEY, "getkey_forvce yields RES_KEY for false alarm"); + + is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for false alarm"); + is_int(key.code.codepoint, 'P', "key.code.codepoint for false alarm"); + is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for false alarm"); + + termkey_destroy(tk); + + return exit_status(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/t/40ti-override.c new/libtermkey-0.20/t/40ti-override.c --- old/libtermkey-0.18/t/40ti-override.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libtermkey-0.20/t/40ti-override.c 2017-03-30 15:17:09.000000000 +0200 @@ -0,0 +1,39 @@ +#include "../termkey.h" +#include "taplib.h" + +#include <stdio.h> + +#include <string.h> + +#define streq(a,b) (!strcmp(a,b)) + +static const char *backspace_is_X(const char *name, const char *val, void *_) +{ + if(streq(name, "key_backspace")) + return "X"; + + return val; +} + +int main(int argc, char *argv[]) +{ + TermKey *tk; + TermKeyKey key; + + plan_tests(3); + + tk = termkey_new_abstract("vt100", TERMKEY_FLAG_NOSTART); + termkey_hook_terminfo_getstr(tk, &backspace_is_X, NULL); + termkey_start(tk); + + termkey_push_bytes(tk, "X", 1); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after X"); + + is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type after X"); + is_int(key.code.sym, TERMKEY_SYM_BACKSPACE, "key.code.sym after X"); + + termkey_destroy(tk); + + return exit_status(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/termkey-internal.h new/libtermkey-0.20/termkey-internal.h --- old/libtermkey-0.18/termkey-internal.h 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/termkey-internal.h 2017-03-30 15:17:09.000000000 +0200 @@ -44,6 +44,9 @@ struct termios restore_termios; char restore_termios_valid; + TermKey_Terminfo_Getstr_Hook *ti_getstr_hook; + void *ti_getstr_hook_data; + int waittime; // msec char is_closed; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/termkey.c new/libtermkey-0.20/termkey.c --- old/libtermkey-0.18/termkey.c 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/termkey.c 2017-03-30 15:17:09.000000000 +0200 @@ -159,6 +159,12 @@ fprintf(stderr, "Mode report mode=%s %d val=%d\n", initial == '?' ? "DEC" : "ANSI", mode, value); } break; + case TERMKEY_TYPE_DCS: + fprintf(stderr, "Device Control String"); + break; + case TERMKEY_TYPE_OSC: + fprintf(stderr, "Operating System Control"); + break; case TERMKEY_TYPE_UNKNOWN_CSI: fprintf(stderr, "unknown CSI\n"); break; @@ -278,6 +284,9 @@ tk->restore_termios_valid = 0; + tk->ti_getstr_hook = NULL; + tk->ti_getstr_hook_data = NULL; + tk->waittime = 50; /* msec */ tk->is_closed = 0; @@ -404,7 +413,7 @@ if(!termkey_init(tk, term)) goto abort; - if(!termkey_start(tk)) + if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk)) goto abort; return tk; @@ -429,9 +438,14 @@ return NULL; } - termkey_start(tk); + if(!(flags & TERMKEY_FLAG_NOSTART) && !termkey_start(tk)) + goto abort; return tk; + +abort: + free(tk); + return NULL; } void termkey_free(TermKey *tk) @@ -458,6 +472,12 @@ termkey_free(tk); } +void termkey_hook_terminfo_getstr(TermKey *tk, TermKey_Terminfo_Getstr_Hook *hookfn, void *data) +{ + tk->ti_getstr_hook = hookfn; + tk->ti_getstr_hook_data = data; +} + int termkey_start(TermKey *tk) { if(tk->is_started) @@ -729,7 +749,13 @@ static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key) { - if(codepoint < 0x20) { + if(codepoint == 0) { + // ASCII NUL = Ctrl-Space + key->type = TERMKEY_TYPE_KEYSYM; + key->code.sym = TERMKEY_SYM_SPACE; + key->modifiers = TERMKEY_KEYMOD_CTRL; + } + else if(codepoint < 0x20) { // C0 range key->code.codepoint = 0; key->modifiers = 0; @@ -793,15 +819,15 @@ int flags = tk->canonflags; if(flags & TERMKEY_CANON_SPACESYMBOL) { - if(key->type == TERMKEY_TYPE_UNICODE && key->code.number == 0x20) { + if(key->type == TERMKEY_TYPE_UNICODE && key->code.codepoint == 0x20) { key->type = TERMKEY_TYPE_KEYSYM; key->code.sym = TERMKEY_SYM_SPACE; } } else { if(key->type == TERMKEY_TYPE_KEYSYM && key->code.sym == TERMKEY_SYM_SPACE) { - key->type = TERMKEY_TYPE_UNICODE; - key->code.number = 0x20; + key->type = TERMKEY_TYPE_UNICODE; + key->code.codepoint = 0x20; fill_utf8(key); } } @@ -1372,6 +1398,12 @@ else l = snprintf(buffer + pos, len - pos, "Mode(%d=%d)", mode, value); } + case TERMKEY_TYPE_DCS: + l = snprintf(buffer + pos, len - pos, "DCS"); + break; + case TERMKEY_TYPE_OSC: + l = snprintf(buffer + pos, len - pos, "OSC"); + break; case TERMKEY_TYPE_UNKNOWN_CSI: l = snprintf(buffer + pos, len - pos, "CSI %c", key->code.number & 0xff); break; @@ -1500,6 +1532,9 @@ return col1 - col2; } break; + case TERMKEY_TYPE_DCS: + case TERMKEY_TYPE_OSC: + return key1p - key2p; case TERMKEY_TYPE_MODEREPORT: { int initial1, initial2, mode1, mode2, value1, value2; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/termkey.h new/libtermkey-0.20/termkey.h --- old/libtermkey-0.18/termkey.h 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/termkey.h 2017-03-30 15:17:09.000000000 +0200 @@ -9,7 +9,7 @@ #include <stdlib.h> #define TERMKEY_VERSION_MAJOR 0 -#define TERMKEY_VERSION_MINOR 18 +#define TERMKEY_VERSION_MINOR 20 #define TERMKEY_CHECK_VERSION \ termkey_check_version(TERMKEY_VERSION_MAJOR, TERMKEY_VERSION_MINOR) @@ -98,6 +98,8 @@ TERMKEY_TYPE_MOUSE, TERMKEY_TYPE_POSITION, TERMKEY_TYPE_MODEREPORT, + TERMKEY_TYPE_DCS, + TERMKEY_TYPE_OSC, /* add other recognised types here */ TERMKEY_TYPE_UNKNOWN_CSI = -1 @@ -151,7 +153,8 @@ TERMKEY_FLAG_NOTERMIOS = 1 << 4, /* Do not make initial termios calls on construction */ TERMKEY_FLAG_SPACESYMBOL = 1 << 5, /* Sets TERMKEY_CANON_SPACESYMBOL */ 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 */ + TERMKEY_FLAG_EINTR = 1 << 7, /* Return ERROR on signal (EINTR) rather than retry */ + TERMKEY_FLAG_NOSTART = 1 << 8 /* Do not call termkey_start() in constructor */ }; enum { @@ -166,6 +169,10 @@ void termkey_free(TermKey *tk); void termkey_destroy(TermKey *tk); +/* Mostly-undocumented hooks for doing evil evil things */ +typedef const char *TermKey_Terminfo_Getstr_Hook(const char *name, const char *value, void *data); +void termkey_hook_terminfo_getstr(TermKey *tk, TermKey_Terminfo_Getstr_Hook *hookfn, void *data); + int termkey_start(TermKey *tk); int termkey_stop(TermKey *tk); int termkey_is_started(TermKey *tk); @@ -210,6 +217,8 @@ TermKeyResult termkey_interpret_csi(TermKey *tk, const TermKeyKey *key, long args[], size_t *nargs, unsigned long *cmd); +TermKeyResult termkey_interpret_string(TermKey *tk, const TermKeyKey *key, const char **strp); + typedef enum { TERMKEY_FORMAT_LONGMOD = 1 << 0, /* Shift-... instead of S-... */ TERMKEY_FORMAT_CARETCTRL = 1 << 1, /* ^X instead of C-X */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libtermkey-0.18/termkey.pc.in new/libtermkey-0.20/termkey.pc.in --- old/libtermkey-0.18/termkey.pc.in 2015-10-06 23:52:28.000000000 +0200 +++ new/libtermkey-0.20/termkey.pc.in 2017-03-30 15:17:09.000000000 +0200 @@ -3,6 +3,6 @@ Name: termkey Description: Abstract terminal key input library -Version: 0.18 +Version: 0.20 Libs: -L${libdir} -ltermkey Cflags: -I${includedir}
