Skip to content

Commit 7e556af

Browse files
committed
HTML cheatsheet talon side
1 parent 486d167 commit 7e556af

File tree

4 files changed

+153
-46
lines changed

4 files changed

+153
-46
lines changed

cursorless-talon/src/cheatsheet/cheat_sheet.py

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,57 @@ def draw_value(self, canvas, text):
293293
class Actions:
294294
def cursorless_cheat_sheet_toggle():
295295
"""Toggle cursorless cheat sheet"""
296-
global cheat_sheet
297-
if cheat_sheet:
298-
actions.mode.disable("user.cursorless_cheat_sheet")
299-
cheat_sheet.close()
300-
cheat_sheet = None
301-
else:
302-
cheat_sheet = CheatSheet()
303-
actions.mode.enable("user.cursorless_cheat_sheet")
296+
actions.user.vscode_with_plugin(
297+
"cursorless.showCheatsheet", actions.user.cursorless_cheat_sheet_get_json()
298+
)
299+
300+
def cursorless_cheat_sheet_get_json():
301+
"""Get cursorless cheat sheet json"""
302+
return {
303+
"sections": [
304+
{
305+
"name": "Actions",
306+
"id": "actions",
307+
"items": get_actions(),
308+
},
309+
{
310+
"name": "Scopes",
311+
"id": "scopes",
312+
"items": get_scopes(),
313+
},
314+
{
315+
"name": "Paired delimiters",
316+
"id": "paired-delimiters",
317+
"items": get_lists(
318+
[
319+
"wrapper_only_paired_delimiter",
320+
"wrapper_selectable_paired_delimiter",
321+
"selectable_only_paired_delimiter",
322+
]
323+
),
324+
},
325+
{
326+
"name": "Special marks",
327+
"id": "special-marks",
328+
"items": get_list("special_mark"),
329+
},
330+
{
331+
"name": "Positions",
332+
"id": "positions",
333+
"items": get_list("position"),
334+
},
335+
{
336+
"name": "Colors",
337+
"id": "colors",
338+
"items": get_list("hat_color"),
339+
},
340+
{
341+
"name": "Shapes",
342+
"id": "shapes",
343+
"items": get_list("hat_shape"),
344+
},
345+
]
346+
}
304347

305348
def cursorless_open_instructions():
306349
"""Open web page with cursorless instructions"""

cursorless-talon/src/cheatsheet/get_list.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,38 @@ def get_list(name, descriptions=None):
1010
descriptions = {}
1111

1212
items = get_raw_list(name)
13-
if isinstance(items, dict):
14-
make_dict_readable(items, descriptions)
15-
return items
13+
item_dict = items if isinstance(items, dict) else {item: item for item in items}
14+
15+
return make_dict_readable(name, item_dict, descriptions)
1616

1717

1818
def get_lists(names: list[str], descriptions=None):
19-
items = sorted(
20-
item for name in names for item in get_list(name, descriptions).items()
21-
)
22-
return {key: value for key, value in items}
19+
20+
return [item for name in names for item in get_list(name, descriptions)]
2321

2422

2523
def get_raw_list(name):
2624
cursorless_list_name = get_cursorless_list_name(name)
2725
return registry.lists[cursorless_list_name][0].copy()
2826

2927

30-
def make_dict_readable(dict, descriptions=None):
28+
def make_dict_readable(type: str, dict, descriptions=None):
3129
if descriptions is None:
3230
descriptions = {}
3331

34-
for k in dict:
35-
desc = dict[k]
36-
if desc in descriptions:
37-
desc = descriptions[desc]
38-
else:
39-
desc = make_readable(desc)
40-
dict[k] = desc
32+
return [
33+
{
34+
"identifier": value,
35+
"type": type,
36+
"spokenForms": [
37+
{
38+
"spokenForm": key,
39+
"description": descriptions.get(value, make_readable(value)),
40+
}
41+
],
42+
}
43+
for key, value in dict.items()
44+
]
4145

4246

4347
def make_readable(text):

cursorless-talon/src/cheatsheet/sections/actions.py

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,84 @@ def get_actions():
3131
get_raw_list("source_destination_connective").keys()
3232
)[0]
3333

34-
make_dict_readable(
35-
simple_actions,
34+
return [
35+
*make_dict_readable(
36+
"action",
37+
simple_actions,
38+
{
39+
"callAsFunction": "Call T on S",
40+
},
41+
),
3642
{
37-
"callAsFunction": "Call T on S",
43+
"identifier": "replaceWithTarget",
44+
"type": "action",
45+
"spokenForms": [
46+
{
47+
"spokenForm": f"{complex_actions['replaceWithTarget']} <T1> {source_destination_connective} <T2>",
48+
"description": "Replace T2 with T1",
49+
},
50+
{
51+
"spokenForm": f"{complex_actions['replaceWithTarget']} <T>",
52+
"description": "Replace S with T",
53+
},
54+
],
3855
},
39-
)
40-
return {
41-
**simple_actions,
42-
f"{complex_actions['replaceWithTarget']} <T1> {source_destination_connective} <T2>": "Replace T2 with T1",
43-
f"{complex_actions['replaceWithTarget']} <T>": "Replace S with T",
44-
f"{complex_actions['moveToTarget']} <T1> {source_destination_connective} <T2>": "Move T1 to T2",
45-
f"{complex_actions['moveToTarget']} <T>": "Move T to S",
46-
f"{complex_actions['swapTargets']} <T1> {swap_connective} <T2>": "Swap T1 with T2",
47-
f"{complex_actions['swapTargets']} {swap_connective} <T>": "Swap S with T",
48-
f"{complex_actions['applyFormatter']} <F> at <T>": "Reformat T as F",
49-
f"<P> {complex_actions['wrapWithPairedDelimiter']} <T>": "Wrap T with P",
50-
f"<P> {complex_actions['rewrap']} <T>": "Rewrap T with P",
51-
}
56+
{
57+
"identifier": "moveToTarget",
58+
"type": "action",
59+
"spokenForms": [
60+
{
61+
"spokenForm": f"{complex_actions['moveToTarget']} <T1> {source_destination_connective} <T2>",
62+
"description": "Move T1 to T2",
63+
},
64+
{
65+
"spokenForm": f"{complex_actions['moveToTarget']} <T>",
66+
"description": "Move T to S",
67+
},
68+
],
69+
},
70+
{
71+
"identifier": "swapTargets",
72+
"type": "action",
73+
"spokenForms": [
74+
{
75+
"spokenForm": f"{complex_actions['swapTargets']} <T1> {swap_connective} <T2>",
76+
"description": "Swap T1 with T2",
77+
},
78+
{
79+
"spokenForm": f"{complex_actions['swapTargets']} {swap_connective} <T>",
80+
"description": "Swap S with T",
81+
},
82+
],
83+
},
84+
{
85+
"identifier": "applyFormatter",
86+
"type": "action",
87+
"spokenForms": [
88+
{
89+
"spokenForm": f"{complex_actions['applyFormatter']} <F> at <T>",
90+
"description": "Reformat T as F",
91+
}
92+
],
93+
},
94+
{
95+
"identifier": "wrapWithPairedDelimiter",
96+
"type": "action",
97+
"spokenForms": [
98+
{
99+
"spokenForm": f"<P> {complex_actions['wrapWithPairedDelimiter']} <T>",
100+
"description": "Wrap T with P",
101+
}
102+
],
103+
},
104+
{
105+
"identifier": "rewrap",
106+
"type": "action",
107+
"spokenForms": [
108+
{
109+
"spokenForm": f"<P> {complex_actions['rewrap']} <T>",
110+
"description": "Rewrap T with P",
111+
}
112+
],
113+
},
114+
]

cursorless-talon/src/cheatsheet/sections/scopes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33

44
def get_scopes():
5-
return {
6-
**get_lists(
7-
["scope_type", "subtoken_scope_type"],
8-
{"argumentOrParameter": "Argument"},
9-
),
10-
"<P>": "Paired delimiter",
11-
}
5+
return get_lists(
6+
["scope_type", "subtoken_scope_type"],
7+
{"argumentOrParameter": "Argument"},
8+
)

0 commit comments

Comments
 (0)