-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.py
More file actions
44 lines (39 loc) · 1.8 KB
/
commands.py
File metadata and controls
44 lines (39 loc) · 1.8 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
#!/usr/bin/env python3
def parse_command(transcript: str, correction_active: bool = False):
stripped = (transcript or "").strip()
lowered = stripped.lower()
if lowered == "scratch that":
return {"kind": "scratch", "display": ""}
if lowered == "new paragraph":
return {"kind": "insert", "text": "\n\n", "display": "\\n\\n"}
if lowered == "new line":
return {"kind": "insert", "text": "\n", "display": "\\n"}
if lowered == "bullet":
return {"kind": "insert", "text": "\n- ", "display": "- "}
if lowered.startswith("bullet "):
text = stripped[7:].strip()
return {"kind": "insert", "text": f"\n- {text}", "display": f"- {text}"}
if lowered.startswith("actually "):
text = stripped[9:].strip()
if text and correction_active:
return {"kind": "replace", "text": text, "display": text}
# Punctuation commands
if lowered == "comma":
return {"kind": "insert", "text": ", ", "display": ","}
if lowered in ("period", "full stop"):
return {"kind": "insert", "text": ". ", "display": "."}
if lowered == "question mark":
return {"kind": "insert", "text": "? ", "display": "?"}
if lowered in ("exclamation mark", "exclamation point"):
return {"kind": "insert", "text": "! ", "display": "!"}
if lowered == "open quote":
return {"kind": "insert", "text": "\u201c", "display": "\u201c"}
if lowered == "close quote":
return {"kind": "insert", "text": "\u201d", "display": "\u201d"}
if lowered == "dash":
return {"kind": "insert", "text": " -- ", "display": "--"}
if lowered == "colon":
return {"kind": "insert", "text": ": ", "display": ":"}
if lowered == "semicolon":
return {"kind": "insert", "text": "; ", "display": ";"}
return None