-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstd.py
121 lines (98 loc) · 3.83 KB
/
std.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from talon.voice import Word, Context, Key, Rep, Str, press
from talon import ctrl
import string
# If you're used to VC alphabet, use the line below instead
#alpha_alt = 'arch brov char dell etch fomp goof hark ice jinks koop lug mowsh nerb ork pooch quash rosh souk teek unks verge womp trex yang zooch'.split()
alpha_alt = 'air bat cap die each fail gone harm sit jinks crash look mad near odd pit quest red sun trap urge vest whale box yang sap'.split()
alnum = list(zip(alpha_alt, string.ascii_lowercase)) + \
[(str(i), str(i)) for i in range(0, 10)]
alpha = {}
alpha.update(dict(alnum))
alpha.update({'ship %s' % word: letter for word,
letter in zip(alpha_alt, string.ascii_uppercase)})
alpha.update({'control %s' % k: Key('ctrl-%s' % v) for k, v in alnum})
alpha.update({'command %s' % k: Key('cmd-%s' % v) for k, v in alnum})
alpha.update({'command shift %s' % k: Key('ctrl-shift-%s' % v)
for k, v in alnum})
alpha.update({'alt %s' % k: Key('alt-%s' % v) for k, v in alnum})
mapping = {
'semicolon': ';',
r'new-line': '\n',
r'new-paragraph': '\n\n',
}
def parse_word(word):
word = word.lstrip('\\').split('\\', 1)[0]
word = mapping.get(word, word)
return word
def text(m):
tmp = [str(s).lower() for s in m.dgndictation[0]._words]
words = [parse_word(word) for word in tmp]
Str(' '.join(words))(None)
def word(m):
tmp = [str(s).lower() for s in m.dgnwords[0]._words]
words = [parse_word(word) for word in tmp]
Str(' '.join(words))(None)
def surround(by):
def func(i, word, last):
if i == 0:
word = by + word
if last:
word += by
return word
return func
def rot13(i, word, _):
out = ''
for c in word.lower():
if c in string.ascii_lowercase:
c = chr((((ord(c) - ord('a')) + 13) % 26) + ord('a'))
out += c
return out
formatters = {
'dunder': (True, lambda i, word, _: '__%s__' % word if i == 0 else word),
'cram': (True, lambda i, word, _: word if i == 0 else word.capitalize()),
'pathway': (True, lambda i, word, _: word if i == 0 else '/'+word),
'dotsway': (True, lambda i, word, _: word if i == 0 else '.'+word),
'snake': (True, lambda i, word, _: word if i == 0 else '_'+word),
'yellsnik': (True, lambda i, word, _: word.capitalize() if i == 0 else '_'+word.capitalize()),
'smash': (True, lambda i, word, _: word),
'dollcram': (True, lambda i, word, _: '$'+word if i == 0 else word.capitalize()),
'champ': (True, lambda i, word, _: word.capitalize() if i == 0 else " "+word),
'lowcram': (True, lambda i, word, _: '@'+word if i == 0 else word.capitalize()),
'criff': (True, lambda i, word, _: word.capitalize()),
'spine': (True, lambda i, word, _: word if i == 0 else '-'+word),
'title': (False, lambda i, word, _: word.capitalize()),
'yeller': (False, lambda i, word, _: word.upper()),
'dub-string': (False, surround('"')),
'string': (False, surround("'")),
'padded': (False, surround(" ")),
'rot thirteen': (False, rot13),
}
def FormatText(m):
fmt = []
for w in m._words:
if isinstance(w, Word):
fmt.append(w.word)
words = [str(s).lower() for s in m.dgndictation[0]._words]
tmp = []
spaces = True
for i, word in enumerate(words):
word = parse_word(word)
for name in reversed(fmt):
smash, func = formatters[name]
word = func(i, word, i == len(words)-1)
spaces = spaces and not smash
tmp.append(word)
words = tmp
sep = ' '
if not spaces:
sep = ''
Str(sep.join(words))(None)
ctx = Context('input')
keymap = {}
keymap.update(alpha)
keymap.update({
'phrase <dgndictation> [over]': text,
'word <dgnwords>': word,
'(%s)+ <dgndictation>' % (' | '.join(formatters)): FormatText,
})
ctx.keymap(keymap)