-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathcommand.py
More file actions
142 lines (120 loc) · 3.76 KB
/
Copy pathcommand.py
File metadata and controls
142 lines (120 loc) · 3.76 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from typing import Any
from talon import Module, actions, speech_system
mod = Module()
last_phrase = None
def on_phrase(d):
global last_phrase
last_phrase = d
speech_system.register("pre:phrase", on_phrase)
class NotSet:
def __repr__(self):
return "<argument not set>"
@mod.action_class
class Actions:
def cursorless_single_target_command(
action: str,
target: dict,
arg1: Any = NotSet,
arg2: Any = NotSet,
arg3: Any = NotSet,
):
"""Execute single-target cursorless command"""
actions.user.cursorless_multiple_target_command(
action, [target], arg1, arg2, arg3
)
def cursorless_single_target_command_no_wait(
action: str,
target: dict,
arg1: Any = NotSet,
arg2: Any = NotSet,
arg3: Any = NotSet,
):
"""Execute single-target cursorless command"""
actions.user.cursorless_multiple_target_command_no_wait(
action, [target], arg1, arg2, arg3
)
def cursorless_single_target_command_with_arg_list(
action: str, target: str, args: list[Any]
):
"""Execute single-target cursorless command with argument list"""
actions.user.cursorless_single_target_command(
action,
target,
*args,
)
def cursorless_single_target_command_with_arg_list(
action: str, target: str, args: list[Any]
):
"""Execute single-target cursorless command with argument list"""
actions.user.cursorless_single_target_command(
action,
target,
*args,
)
def cursorless_single_target_command_get(
action: str,
target: dict,
arg1: Any = NotSet,
arg2: Any = NotSet,
arg3: Any = NotSet,
):
"""Execute single-target cursorless command and return result"""
return actions.user.vscode_get(
"cursorless.command",
construct_cursorless_command_argument(
action=action,
targets=[target],
args=[x for x in [arg1, arg2, arg3] if x is not NotSet],
),
)
def cursorless_multiple_target_command(
action: str,
targets: list[dict],
arg1: any = NotSet,
arg2: any = NotSet,
arg3: any = NotSet,
):
"""Execute multi-target cursorless command"""
actions.user.vscode_with_plugin_and_wait(
"cursorless.command",
construct_cursorless_command_argument(
action=action,
targets=targets,
args=[x for x in [arg1, arg2, arg3] if x is not NotSet],
),
)
def cursorless_multiple_target_command_no_wait(
action: str,
targets: list[dict],
arg1: any = NotSet,
arg2: any = NotSet,
arg3: any = NotSet,
):
"""Execute multi-target cursorless command"""
actions.user.vscode_with_plugin(
"cursorless.command",
construct_cursorless_command_argument(
action=action,
targets=targets,
args=[x for x in [arg1, arg2, arg3] if x is not NotSet],
),
)
def construct_cursorless_command_argument(
action: str, targets: list[dict], args: list[any]
):
try:
use_pre_phrase_snapshot = actions.user.did_emit_pre_phrase_signal()
except KeyError:
use_pre_phrase_snapshot = False
return {
"version": 2,
"spokenForm": get_spoken_form(),
"action": {
"name": action,
"args": args,
},
"targets": targets,
"usePrePhraseSnapshot": use_pre_phrase_snapshot,
}
def get_spoken_form():
return " ".join(last_phrase["phrase"])