-
Notifications
You must be signed in to change notification settings - Fork 10
/
term-keys-wezterm.el
82 lines (64 loc) · 2.67 KB
/
term-keys-wezterm.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;; term-keys-wezterm.el --- term-keys support for wezterm
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This file contains supplementary code for aiding in the
;; configuration of the wezterm terminal emulator to interoperate with
;; the term-keys package.
;; For more information, please see the accompanying README.md file.
;;; Code:
(require 'term-keys)
(require 'term-keys-glfw-mods)
(defun term-keys/wezterm-format-key (keymap mods)
"Format key in wezterm syntax according to mods."
(or ; Apply shift
(and (elt mods 0) ; With Shift?
(elt keymap 13)) ; Use shifted column
(elt keymap 12))) ; Use non-shifted column
(defun term-keys/wezterm-format-mods (mods)
"Format modifiers in wezterm syntax.
Returns the wezterm key combination string corresponding to the
KEYMAP and modifier state MODS."
(string-join
(cl-loop for modflag across mods
for index from 0
if modflag
collect
(elt term-keys/glfw-modifier-map index))
"|"))
(defun term-keys/wezterm-conf ()
"Construct wezterm configuration (wezterm.lua fragment).
This function returns, as a string, the wezterm.lua key map lines
necessary to configure wezterm to encode term-keys key sequences,
according to the term-keys configuration."
(concat "enable_kitty_keyboard = true,\nkeys = {\n"
(apply #'concat
(term-keys/iterate-keys
(lambda (index keymap mods)
(format " {key = \"%s\", mods = \"%s\", action = wezterm.action{SendString=\"%s\"}},\n"
(term-keys/wezterm-format-key keymap mods)
(term-keys/wezterm-format-mods mods)
(mapconcat
(lambda (c) (format "\\x%02x" c))
(append
term-keys/prefix
(term-keys/encode-key index mods)
term-keys/suffix
nil)
"")))))
"},"))
(provide 'term-keys-wezterm)
;;; term-keys-wezterm.el ends here