2019-08-07 14:32:51 -05:00
|
|
|
# Author: Jeremy Hayes
|
2021-02-10 14:42:21 -06:00
|
|
|
# Modified from: Brandon Lovrien version
|
|
|
|
# This script includes commands used for Terminal coding
|
2019-08-07 14:32:51 -05:00
|
|
|
|
2021-02-10 14:42:21 -06:00
|
|
|
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
|
2022-02-10 07:19:17 -06:00
|
|
|
import os
|
2019-08-07 14:32:51 -05:00
|
|
|
|
|
|
|
class TerminalEnabler(CompoundRule):
|
|
|
|
spec = "Activate Terminal" # Spoken form of command.
|
|
|
|
|
|
|
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
|
|
|
TerminalBootstrap.disable()
|
|
|
|
TerminalGrammar.enable()
|
|
|
|
s = "Terminal grammar activated"
|
2021-02-12 12:26:10 -06:00
|
|
|
print (s)
|
2022-02-10 07:19:17 -06:00
|
|
|
os.system('echo "{0}" | festival --tts'.format(s))
|
|
|
|
|
2019-08-07 14:32:51 -05:00
|
|
|
class TerminalDisabler(CompoundRule):
|
|
|
|
spec = "switch language" # Spoken form of command.
|
|
|
|
|
|
|
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
|
|
|
TerminalGrammar.disable()
|
|
|
|
TerminalBootstrap.enable()
|
|
|
|
s = "Terminal grammar deactivated"
|
2021-02-12 12:26:10 -06:00
|
|
|
print (s)
|
2022-02-10 07:19:17 -06:00
|
|
|
os.system('echo "{0}" | festival --tts'.format(s))
|
2019-08-07 14:32:51 -05:00
|
|
|
|
|
|
|
class TerminalTestRule(CompoundRule):
|
|
|
|
spec = "test Terminal" # Spoken form of command.
|
|
|
|
|
|
|
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
2021-02-12 12:26:10 -06:00
|
|
|
print ("Terminal grammar tested")
|
2019-08-07 14:32:51 -05:00
|
|
|
|
|
|
|
|
2021-02-10 14:42:21 -06:00
|
|
|
class TerminalTags(MappingRule):
|
2019-08-07 14:32:51 -05:00
|
|
|
|
|
|
|
mapping = {
|
2022-02-10 07:19:17 -06:00
|
|
|
"file copy": Text("cp"),
|
|
|
|
"file list": Text("ls"),
|
|
|
|
"file move": Text("mv"),
|
2021-02-10 14:42:21 -06:00
|
|
|
"force remove <tagname>": Text("rm -rf %(tagname)s"),
|
|
|
|
"make directory": Text("mkdir"),
|
|
|
|
"nano": Text("nano" ),
|
2022-02-10 07:19:17 -06:00
|
|
|
"node package manager": Text("npm" ),
|
|
|
|
"node": Text("node" ),
|
|
|
|
"node version manager": Text("nvm" ),
|
|
|
|
"python": Text("python3" ),
|
|
|
|
"pip": Text("pip3" ),
|
2021-02-10 14:42:21 -06:00
|
|
|
"remove": Text( "rm" ),
|
|
|
|
|
|
|
|
# used to specify tag attributes
|
|
|
|
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
|
|
|
|
"<attribute> attribute": Text( ' %(attribute)s=""' ) + Key( "left" ),
|
2019-08-07 14:32:51 -05:00
|
|
|
|
|
|
|
}
|
2021-02-10 14:42:21 -06:00
|
|
|
extras = [
|
|
|
|
Choice("attribute", {
|
|
|
|
"ID": "id",
|
|
|
|
"class": "class",
|
|
|
|
"style": "style",
|
|
|
|
"title": "title",
|
|
|
|
"SRC": "src",
|
|
|
|
"HREF": "href",
|
|
|
|
"type": "type",
|
|
|
|
"value": "value",
|
|
|
|
"ng": "ng-",
|
|
|
|
}
|
|
|
|
),
|
|
|
|
Choice("tagname", {
|
|
|
|
"anchor": "a",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
# Code for initial setup of the Terminal grammar
|
2019-08-07 14:32:51 -05:00
|
|
|
TerminalBootstrap = Grammar("Terminal bootstrap") # Create a grammar to contain the command rule.
|
|
|
|
TerminalBootstrap.add_rule(TerminalEnabler())
|
|
|
|
TerminalBootstrap.load()
|
|
|
|
|
2021-02-10 14:42:21 -06:00
|
|
|
|
2019-08-07 14:32:51 -05:00
|
|
|
TerminalGrammar = Grammar("Terminal grammar")
|
|
|
|
TerminalGrammar.add_rule(TerminalTestRule())
|
|
|
|
TerminalGrammar.add_rule(TerminalDisabler())
|
2021-02-10 14:42:21 -06:00
|
|
|
TerminalGrammar.add_rule(TerminalTags())
|
2019-08-07 14:32:51 -05:00
|
|
|
TerminalGrammar.load()
|
|
|
|
TerminalGrammar.disable()
|
|
|
|
|
|
|
|
# Unload function which will be called by natlink at unload time.
|
|
|
|
def unload():
|
|
|
|
global TerminalGrammar
|
|
|
|
if TerminalGrammar: TerminalGrammar.unload()
|
|
|
|
TerminalGrammar = None
|