Get rid of the send_text_map code
Just transform send_text directives in the config file to map directives.
This commit is contained in:
parent
1d45a831ef
commit
4dc6918b13
@ -12,7 +12,7 @@ from .fast_data_types import (
|
||||
destroy_sprite_map, glfw_post_empty_event, layout_sprite_map
|
||||
)
|
||||
from .fonts.render import prerender, resize_fonts, set_font_family
|
||||
from .keys import get_key_map, get_sent_data, get_shortcut
|
||||
from .keys import get_key_map, get_shortcut
|
||||
from .session import create_session
|
||||
from .tabs import SpecialWindow, TabManager
|
||||
from .utils import (
|
||||
@ -199,13 +199,6 @@ class Boss:
|
||||
passthrough = f(*key_action.args)
|
||||
if passthrough is not True:
|
||||
return True
|
||||
key, scancode, action, mods = self.current_key_press_info
|
||||
data = get_sent_data(
|
||||
self.opts.send_text_map, key, scancode, mods, window, action
|
||||
)
|
||||
if data:
|
||||
window.write_to_child(data)
|
||||
return True
|
||||
return False
|
||||
|
||||
def combine(self, *actions):
|
||||
|
||||
@ -175,7 +175,7 @@ def parse_send_text_bytes(text):
|
||||
return ast.literal_eval("'''" + text + "'''").encode('utf-8')
|
||||
|
||||
|
||||
def parse_send_text(val):
|
||||
def parse_send_text(val, keymap):
|
||||
parts = val.split(' ')
|
||||
|
||||
def abort(msg):
|
||||
@ -187,28 +187,10 @@ def parse_send_text(val):
|
||||
|
||||
if len(parts) < 3:
|
||||
return abort('Incomplete')
|
||||
|
||||
text = ' '.join(parts[2:])
|
||||
mode, sc = parts[:2]
|
||||
mods, key = parse_shortcut(sc.strip())
|
||||
if key is None:
|
||||
return abort('Invalid shortcut')
|
||||
text = parse_send_text_bytes(text)
|
||||
if not text:
|
||||
return abort('Empty text')
|
||||
|
||||
if mode in ('all', '*'):
|
||||
modes = parse_send_text.all_modes
|
||||
else:
|
||||
modes = frozenset(mode.split(',')).intersection(
|
||||
parse_send_text.all_modes
|
||||
)
|
||||
if not modes:
|
||||
return abort('Invalid keyboard modes')
|
||||
return {mode: {(mods, key): text} for mode in modes}
|
||||
|
||||
|
||||
parse_send_text.all_modes = frozenset({'normal', 'application', 'kitty'})
|
||||
text = ' '.join(parts[2:])
|
||||
key_str = '{} send_text {} {}'.format(sc, mode, text)
|
||||
return parse_key(key_str, keymap)
|
||||
|
||||
|
||||
def to_open_url_modifiers(val):
|
||||
@ -285,11 +267,6 @@ def parse_config(lines, check_keys=True):
|
||||
ans = {
|
||||
'keymap': {},
|
||||
'symbol_map': {},
|
||||
'send_text_map': {
|
||||
'kitty': {},
|
||||
'normal': {},
|
||||
'application': {}
|
||||
}
|
||||
}
|
||||
if check_keys:
|
||||
all_keys = defaults._asdict()
|
||||
@ -307,9 +284,8 @@ def parse_config(lines, check_keys=True):
|
||||
ans['symbol_map'].update(parse_symbol_map(val))
|
||||
continue
|
||||
if key == 'send_text':
|
||||
stvals = parse_send_text(val)
|
||||
for k, v in ans['send_text_map'].items():
|
||||
v.update(stvals.get(k, {}))
|
||||
# For legacy compatibility
|
||||
parse_send_text(val, ans['keymap'])
|
||||
continue
|
||||
if check_keys:
|
||||
if key not in all_keys:
|
||||
@ -360,11 +336,6 @@ def merge_configs(defaults, vals):
|
||||
newvals = vals.get(k, {})
|
||||
if k == 'keymap':
|
||||
ans['keymap'] = merge_keymaps(v, newvals)
|
||||
elif k == 'send_text_map':
|
||||
ans[k] = {
|
||||
m: merge_dicts(mm, newvals.get(m, {}))
|
||||
for m, mm in v.items()
|
||||
}
|
||||
else:
|
||||
ans[k] = merge_dicts(v, newvals)
|
||||
else:
|
||||
|
||||
@ -225,13 +225,6 @@ def get_shortcut(keymap, mods, key, scancode):
|
||||
return keymap.get((mods & 0b1111, key))
|
||||
|
||||
|
||||
def get_sent_data(send_text_map, key, scancode, mods, window, action):
|
||||
if action in (defines.GLFW_PRESS, defines.GLFW_REPEAT):
|
||||
m = keyboard_mode_name(window.screen)
|
||||
keymap = send_text_map[m]
|
||||
return keymap.get((mods & 0b1111, key))
|
||||
|
||||
|
||||
def generate_key_table():
|
||||
# To run this, use: python3 . -c "from kitty.keys import *; generate_key_table()"
|
||||
import os
|
||||
|
||||
@ -298,8 +298,6 @@ map ctrl+shift+f11 toggle_fullscreen
|
||||
# to the start of the line (same as pressing the Home key):
|
||||
# map ctrl+alt+a send_text normal Word\x1b[H
|
||||
# map ctrl+alt+a send_text application Word\x1bOH
|
||||
# There is also a legacy syntax for send_text, which looks like:
|
||||
# send_text all ctrl+alt+a some text
|
||||
|
||||
# Symbol mapping (special font for specified unicode code points). Map the
|
||||
# specified unicode codepoints to a particular font. Useful if you need special
|
||||
|
||||
@ -170,16 +170,10 @@ PYWRAP1(set_options) {
|
||||
OPT(select_by_word_characters)[i] = PyUnicode_READ(PyUnicode_KIND(chars), PyUnicode_DATA(chars), i);
|
||||
}
|
||||
OPT(select_by_word_characters_count) = PyUnicode_GET_LENGTH(chars);
|
||||
Py_DECREF(chars);
|
||||
|
||||
GA(keymap); set_special_keys(ret);
|
||||
Py_DECREF(ret); if (PyErr_Occurred()) return NULL;
|
||||
GA(send_text_map);
|
||||
dict_iter(ret) {
|
||||
set_special_keys(value);
|
||||
}}
|
||||
Py_DECREF(ret); if (PyErr_Occurred()) return NULL;
|
||||
|
||||
Py_DECREF(chars);
|
||||
|
||||
PyObject *al = PyObject_GetAttrString(args, "adjust_line_height");
|
||||
if (PyFloat_Check(al)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user