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
|
destroy_sprite_map, glfw_post_empty_event, layout_sprite_map
|
||||||
)
|
)
|
||||||
from .fonts.render import prerender, resize_fonts, set_font_family
|
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 .session import create_session
|
||||||
from .tabs import SpecialWindow, TabManager
|
from .tabs import SpecialWindow, TabManager
|
||||||
from .utils import (
|
from .utils import (
|
||||||
@ -199,13 +199,6 @@ class Boss:
|
|||||||
passthrough = f(*key_action.args)
|
passthrough = f(*key_action.args)
|
||||||
if passthrough is not True:
|
if passthrough is not True:
|
||||||
return 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
|
return False
|
||||||
|
|
||||||
def combine(self, *actions):
|
def combine(self, *actions):
|
||||||
|
|||||||
@ -175,7 +175,7 @@ def parse_send_text_bytes(text):
|
|||||||
return ast.literal_eval("'''" + text + "'''").encode('utf-8')
|
return ast.literal_eval("'''" + text + "'''").encode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def parse_send_text(val):
|
def parse_send_text(val, keymap):
|
||||||
parts = val.split(' ')
|
parts = val.split(' ')
|
||||||
|
|
||||||
def abort(msg):
|
def abort(msg):
|
||||||
@ -187,28 +187,10 @@ def parse_send_text(val):
|
|||||||
|
|
||||||
if len(parts) < 3:
|
if len(parts) < 3:
|
||||||
return abort('Incomplete')
|
return abort('Incomplete')
|
||||||
|
|
||||||
text = ' '.join(parts[2:])
|
|
||||||
mode, sc = parts[:2]
|
mode, sc = parts[:2]
|
||||||
mods, key = parse_shortcut(sc.strip())
|
text = ' '.join(parts[2:])
|
||||||
if key is None:
|
key_str = '{} send_text {} {}'.format(sc, mode, text)
|
||||||
return abort('Invalid shortcut')
|
return parse_key(key_str, keymap)
|
||||||
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'})
|
|
||||||
|
|
||||||
|
|
||||||
def to_open_url_modifiers(val):
|
def to_open_url_modifiers(val):
|
||||||
@ -285,11 +267,6 @@ def parse_config(lines, check_keys=True):
|
|||||||
ans = {
|
ans = {
|
||||||
'keymap': {},
|
'keymap': {},
|
||||||
'symbol_map': {},
|
'symbol_map': {},
|
||||||
'send_text_map': {
|
|
||||||
'kitty': {},
|
|
||||||
'normal': {},
|
|
||||||
'application': {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if check_keys:
|
if check_keys:
|
||||||
all_keys = defaults._asdict()
|
all_keys = defaults._asdict()
|
||||||
@ -307,9 +284,8 @@ def parse_config(lines, check_keys=True):
|
|||||||
ans['symbol_map'].update(parse_symbol_map(val))
|
ans['symbol_map'].update(parse_symbol_map(val))
|
||||||
continue
|
continue
|
||||||
if key == 'send_text':
|
if key == 'send_text':
|
||||||
stvals = parse_send_text(val)
|
# For legacy compatibility
|
||||||
for k, v in ans['send_text_map'].items():
|
parse_send_text(val, ans['keymap'])
|
||||||
v.update(stvals.get(k, {}))
|
|
||||||
continue
|
continue
|
||||||
if check_keys:
|
if check_keys:
|
||||||
if key not in all_keys:
|
if key not in all_keys:
|
||||||
@ -360,11 +336,6 @@ def merge_configs(defaults, vals):
|
|||||||
newvals = vals.get(k, {})
|
newvals = vals.get(k, {})
|
||||||
if k == 'keymap':
|
if k == 'keymap':
|
||||||
ans['keymap'] = merge_keymaps(v, newvals)
|
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:
|
else:
|
||||||
ans[k] = merge_dicts(v, newvals)
|
ans[k] = merge_dicts(v, newvals)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -225,13 +225,6 @@ def get_shortcut(keymap, mods, key, scancode):
|
|||||||
return keymap.get((mods & 0b1111, key))
|
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():
|
def generate_key_table():
|
||||||
# To run this, use: python3 . -c "from kitty.keys import *; generate_key_table()"
|
# To run this, use: python3 . -c "from kitty.keys import *; generate_key_table()"
|
||||||
import os
|
import os
|
||||||
|
|||||||
@ -298,8 +298,6 @@ map ctrl+shift+f11 toggle_fullscreen
|
|||||||
# to the start of the line (same as pressing the Home key):
|
# 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 normal Word\x1b[H
|
||||||
# map ctrl+alt+a send_text application Word\x1bOH
|
# 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
|
# Symbol mapping (special font for specified unicode code points). Map the
|
||||||
# specified unicode codepoints to a particular font. Useful if you need special
|
# 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)[i] = PyUnicode_READ(PyUnicode_KIND(chars), PyUnicode_DATA(chars), i);
|
||||||
}
|
}
|
||||||
OPT(select_by_word_characters_count) = PyUnicode_GET_LENGTH(chars);
|
OPT(select_by_word_characters_count) = PyUnicode_GET_LENGTH(chars);
|
||||||
|
Py_DECREF(chars);
|
||||||
|
|
||||||
GA(keymap); set_special_keys(ret);
|
GA(keymap); set_special_keys(ret);
|
||||||
Py_DECREF(ret); if (PyErr_Occurred()) return NULL;
|
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");
|
PyObject *al = PyObject_GetAttrString(args, "adjust_line_height");
|
||||||
if (PyFloat_Check(al)) {
|
if (PyFloat_Check(al)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user