-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcase.py
49 lines (34 loc) · 991 Bytes
/
case.py
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
from talon.voice import Word, Context, Key, Rep, RepPhrase, Str, press
import string
alpha_alt = 'air bat cap die each fail gone harm sit jury crash look mad '\
'near odd per quest red soon trap urge vest whale box yes zip'.split()
alnum = list(zip(alpha_alt, string.ascii_lowercase)) + \
[(str(i), str(i)) for i in range(0, 10)]
alpha = {}
alpha.update(dict(alnum))
# these help in vim
alpha_up = {
'gate': 'G',
# 'viz.': 'V',
}
case_state = False
def insert_character(m):
c = alpha.get(str(m._words[0]))
if case_state:
press(c.upper())
else:
press(c)
def case_upper(discard):
global case_state
case_state = True
def case_down(discard):
global case_state
case_state = False
context = Context('case')
keymap = {
'upstate': case_upper,
'downstate': case_down,
}
keymap.update({'%s' % k: insert_character for k in alpha})
keymap.update({'%s' % k: '%s' % v for k, v in alpha_up.items()})
context.keymap(keymap)