Implement DCS querying of terminfo data

This commit is contained in:
Kovid Goyal 2016-11-24 12:12:19 +05:30
parent bfeddfa35e
commit bbea86020a
5 changed files with 40 additions and 3 deletions

View File

@ -24,6 +24,7 @@ from .utils import sanitize_title
from .fast_data_types import ( from .fast_data_types import (
BRACKETED_PASTE_START, BRACKETED_PASTE_END, Screen, read_bytes_dump, read_bytes BRACKETED_PASTE_START, BRACKETED_PASTE_END, Screen, read_bytes_dump, read_bytes
) )
from .terminfo import get_capabilities
def handle_unix_signals(): def handle_unix_signals():
@ -246,7 +247,9 @@ class Boss(Thread):
def set_dynamic_color(self, code, value): def set_dynamic_color(self, code, value):
wmap = {10: 'fg', 11: 'bg', 110: 'fg', 111: 'bg'} wmap = {10: 'fg', 11: 'bg', 110: 'fg', 111: 'bg'}
for val in value.decode('utf-8').split(';'): if isinstance(value, bytes):
value = value.decode('utf-8')
for val in value.split(';'):
w = wmap.get(code) w = wmap.get(code)
if w is not None: if w is not None:
if code >= 110: if code >= 110:
@ -260,6 +263,9 @@ class Boss(Thread):
self.pending_color_changes = {} self.pending_color_changes = {}
glfw.glfwPostEmptyEvent() glfw.glfwPostEmptyEvent()
def request_capabilities(self, q):
self.write_to_child(get_capabilities(q))
# actions {{{ # actions {{{
def paste(self, text): def paste(self, text):

View File

@ -51,6 +51,7 @@ PyInit_fast_data_types(void) {
PyModule_AddIntConstant(m, "DECORATION", DECORATION_SHIFT); PyModule_AddIntConstant(m, "DECORATION", DECORATION_SHIFT);
PyModule_AddStringMacro(m, BRACKETED_PASTE_START); PyModule_AddStringMacro(m, BRACKETED_PASTE_START);
PyModule_AddStringMacro(m, BRACKETED_PASTE_END); PyModule_AddStringMacro(m, BRACKETED_PASTE_END);
PyModule_AddStringMacro(m, ERROR_PREFIX);
PyModule_AddIntMacro(m, CURSOR_BLOCK); PyModule_AddIntMacro(m, CURSOR_BLOCK);
PyModule_AddIntMacro(m, CURSOR_BEAM); PyModule_AddIntMacro(m, CURSOR_BEAM);
PyModule_AddIntMacro(m, CURSOR_UNDERLINE); PyModule_AddIntMacro(m, CURSOR_UNDERLINE);

View File

@ -21,6 +21,9 @@ typedef uint64_t color_type;
typedef uint32_t decoration_type; typedef uint32_t decoration_type;
typedef uint32_t combining_type; typedef uint32_t combining_type;
typedef unsigned int index_type; typedef unsigned int index_type;
#define ERROR_PREFIX "[PARSE ERROR]"
#define CELL_SIZE (sizeof(char_type) + sizeof(color_type) + sizeof(decoration_type) + sizeof(combining_type)) #define CELL_SIZE (sizeof(char_type) + sizeof(color_type) + sizeof(decoration_type) + sizeof(combining_type))
// The data cell size must be a multiple of 3 // The data cell size must be a multiple of 3
#define DATA_CELL_SIZE 2 * 3 #define DATA_CELL_SIZE 2 * 3

View File

@ -76,7 +76,7 @@ static void _report_error(PyObject *dump_callback, const char *fmt, ...) {
#define DUMP_UNUSED UNUSED #define DUMP_UNUSED UNUSED
#define REPORT_ERROR(...) fprintf(stderr, "[PARSE ERROR] "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); #define REPORT_ERROR(...) fprintf(stderr, "%s ", ERROR_PREFIX); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n");
#define REPORT_COMMAND(...) #define REPORT_COMMAND(...)
#define REPORT_DRAW(ch) #define REPORT_DRAW(ch)

View File

@ -2,6 +2,8 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from binascii import unhexlify, hexlify
names = 'xterm-kitty', 'KovIdTTY' names = 'xterm-kitty', 'KovIdTTY'
termcap_aliases = { termcap_aliases = {
@ -264,7 +266,7 @@ termcap_aliases.update({
'SF': 'indn', 'SF': 'indn',
# 'Ic': 'initc', # 'Ic': 'initc',
# 'mk': 'invis', # 'mk': 'invis',
'bs': 'kbs', 'kb': 'kbs',
'kl': 'kcub1', 'kl': 'kcub1',
'kd': 'kcud1', 'kd': 'kcud1',
'kr': 'kcuf1', 'kr': 'kcuf1',
@ -318,6 +320,8 @@ termcap_aliases.update({
}) })
queryable_capabilities = numeric_capabilities.copy()
queryable_capabilities.update(string_capabilities)
extra = (bool_capabilities | numeric_capabilities.keys() | string_capabilities.keys()) - set(termcap_aliases.values()) extra = (bool_capabilities | numeric_capabilities.keys() | string_capabilities.keys()) - set(termcap_aliases.values())
if extra: if extra:
raise Exception('Termcap aliases not complete, missing: {}'.format(extra)) raise Exception('Termcap aliases not complete, missing: {}'.format(extra))
@ -335,3 +339,26 @@ def generate_terminfo():
def key_as_bytes(name): def key_as_bytes(name):
ans = string_capabilities[name] ans = string_capabilities[name]
return ans.replace(r'\E', '\033').encode('ascii') return ans.replace(r'\E', '\033').encode('ascii')
def get_capabilities(query_string):
from .fast_data_types import ERROR_PREFIX
ans = []
try:
for q in query_string.split(';'):
name = unhexlify(q).decode('utf-8')
if name == 'TN':
val = names[0]
else:
try:
val = queryable_capabilities[name]
except KeyError:
try:
val = queryable_capabilities[termcap_aliases[name]]
except Exception as e:
print(ERROR_PREFIX, 'Unknown terminfo property:', name)
raise
ans.append(q + '=' + hexlify(str(val)))
return b'\033P1+r' + ';'.join(ans).encode('utf-8') + b'\033\\'
except Exception:
return b'\033P0+r' + query_string.encode('utf-8') + b'\033\\'