def tags(element): elementString = str(element) if element in voidElements: Text("<%s />" % str(element)).execute() else: Text("<%s></%s>" % (elementString, elementString)).execute() Key("left:%s" % (len(elementString) + 3)).execute()
class Bash(MergeRule): mapping = { "pseudo-": Text("sudo "), "change": Text("cd "), "list": Key("l,s,enter"), "sublime": Text("subl "), "home": Text("~/"), "pie": Text("py"), "copy": Key("cs-c"), "copy <t>": Function(copy), "paste": Key("cs-v"), "paste <t>": Function(paste), "make directory": Text("mkdir "), ".Thought": Text(".."), "parent": Text("../"), "remote <ssh_server>": Text('ssh %(ssh_server)s'), "dropbox": Text("cd ~/Dropbox/"), "reset": Key("c-c,c-c,up,enter") } extras = [ Choice('ssh_server', {}), Dictation("t"), ] defaults = { "t": 'default', }
def value(self, node): value = MappingRule.value(self, node) if value == 'tcomment': # ugly hack to get around tComment's not allowing ranges with gcc. value = node.children[0].children[0].children[0].children[1].value() if value in (1, '1', None): return Text('gcc') else: return Text('gc%dj' % (int(value) - 1)) else: return value
def _func(text=""): Text('function ').execute() camel_case_text(text) Text('() {').execute() Key('enter').execute() Key('rbrace').execute() _esc() if (text == ""): Key('k, s-4, h, h, h, i').execute() else: Key('k, o').execute()
def value(self, node): words = node.words() print "format rule:", words #------------------------------------------- # Handle uppercase uppercase = words[0] == 'uppercase' #lowercase = words[0] != 'natural' #if lowercase: # words = [word.lower() for word in words] if uppercase: words = [word.upper() for word in words] words = [word.split('\\', 1)[0].replace('-', '') for word in words] if words[0].lower() in ('uppercase', 'natural'): del words[0] #------------------------------------------- # Handle 'macro' if 'macro' in words[0]: # Get macro to use underscore_formatting_mode words[0] = 'score' # Convert all the words to UPPERCASE words = [word.upper() for word in words] #------------------------------------------- # Handle 'bomb' bomb = None if 'bomb' in words: bomb_point = words.index('bomb') if bomb_point + 1 < len(words): bomb = words[bomb_point + 1:] words = words[:bomb_point] #------------------------------------------- # Process all the words function = getattr(aenea.format, 'format_%s' % words[0].lower()) formatted = function(words[1:]) global lastFormatRuleWords lastFormatRuleWords = words[1:] global lastFormatRuleLength lastFormatRuleLength = len(formatted) # empty formatted causes problems here print " ->", formatted if bomb != None: return Text(formatted) + Mimic(' '.join(bomb)) else: return Text(formatted)
class ChromiumRule(MappingRule): mapping = aenea.configuration.make_grammar_commands('chromium', { 'open frame': Key('c-t'), 'close frame [<n>]': (Key('c-w') + Pause('40')) * Repeat(extra='n'), 'frame [<n>]': Key('c-%(n)d'), 'west [<n>]': Key('cs-tab:%(n)d'), 'east [<n>]': Key('c-tab:%(n)d'), # url 'search [<text>]': Key('c-k') + Text('%(text)s'), 'address': Key('c-l'), # search query # 'selection': Key('c-c') + Key('c-t') + Pause('90') + Key('c-v') + Key('enter'), 'quick search': Key('c-t') + Key('c-v') + Key('enter'), 'voice search': Key('c-1') + Function(mute_microphone), # find on a page 'find [<text>]': Key('c-f') + Text('%(text)s'), 'bind [<text>]': Text('/') + Pause('50') + Text('%(text)s'), 'next [<n>]': Key('c-g:%(n)d'), 'previous [<n>]': Key('cs-g:%(n)d'), 'history': Key('c-h'), 'bookmarks': Key('c-h'), # navigation 'back [<n>]': Key('a-left:%(n)d'), 'reload': Key('c-r'), # 'back [<n>]': Key('a-left:%(n)d'), -> to global 'forward [<n>]': Key('a-right:%(n)d'), # vimium 'link': Key('f'), 'new link': Key('s-f'), 'number [<n>]': Text('%(n)d'), # zoom 'zoom in [<n>]': Key('c-plus:%(n)d'), 'zoom out [<n>]': Key('c-minus:%(n)d'), # scroll slow 'slide': Key('c-0'), }) extras = [IntegerRef('n', 1, 100), Dictation('text')] defaults = { 'n': 1, 'text': '' }
def option(self, alias, option, append_space=True): alias = alias.strip() if alias in self.data['options']: return result_text = option if isinstance(result_text, basestring): result_text = Text(option) if append_space: result_text = Text(' ') + result_text self.data['options'][alias] = result_text return self
def template_preamble(): Key("langle, percent").execute() Key("enter").execute() Text(" @path = \"\"", static=True).execute() Key("enter").execute() Key("backspace, backspace, percent, rangle").execute() Key("enter, enter").execute()
def cap_that(text): # if mode == "normal": # Key("i").execute() text = clean_prose(str(text)) text = upperfirst(text) print "typing: " + text Text(text).execute()
def value(self, node): delegates = node.children[0].children[0].children value = delegates[-1].value() if delegates[0].value() is not None: return Text('%s' % delegates[0].value()) + value else: return value
def git(git_command, name=""): t = "git " if git_command is "clone": t += "clone [email protected]:" elif git_command is "add": t += "add ." elif git_command is "delete": t += "push origin --delete {} && git branch -d {}".format(name, name) elif git_command is "all": t += 'add . && git commit -m "" && git push' elif git_command is "commit": t += 'commit -m ""' Key("left").execute() elif git_command is "pull": t += "pull " elif git_command is "push": t += "push " elif git_command is "checkout": t += "checkout " elif git_command is "init": t += "init " elif git_command is "status": t += "status " else: t += git_command + " " Text(t).execute() if git_command is "all": Key("c-left:3,right:3").execute()
def lower_that_space(text, mode="normal"): # if mode == "normal": # Key("i").execute() text = clean_prose(str(text)) text = text + ' ' print "typing: " + text Text(text).execute()
def value(self, node): words = node.words() print("format rule:", words) leading = (words[0] != 'start') trailing = False #(words[0] != 'end' and words[0] != 'isolated') if words[0] == 'start' or words[0] == 'isolated': words = words[1:] capitalize = (words[0] == 'new') if words[0] == 'new': words = words[1:] words = words[1:] # delete "phrase" if len(words) == 0: return Pause("0") formatted = '' addedWords = False for word in words: special = word.split('\\', 1) if(len(special) > 1 and special[1] != 'pronoun' and special[1] != 'determiner'): formatted += special[0] else: if(addedWords): formatted += ' ' formatted += special[0] addedWords = True if capitalize: formatted = formatted[:1].capitalize() + formatted[1:] if leading: formatted = ' ' + formatted if trailing: formatted += ' ' global lastFormatRuleWords lastFormatRuleWords = words global lastFormatRuleLength lastFormatRuleLength = len(formatted) print(" ->", formatted) return Text(formatted)
def squash_count(n): """Formats n words to the left of the cursor with whitespace removed. Excepting spaces immediately after comma, colon and percent chars. Note: Word count differs between editors and programming languages. The examples are all from Eclipse/Python. Example: "'my new variable' *pause* 'squash 3'" => "mynewvariable". "'my<tab>new variable' *pause* 'squash 3'" => "mynewvariable". "( foo = bar, fee = fye )", 'squash 9'" => "(foo=bar, fee=fye)" """ saveText = _get_clipboard_text() cutText = _select_and_cut_text(n) if cutText: endSpace = cutText.endswith(' ') text = _cleanup_text(cutText) newText = ''.join(text.split(' ')) if endSpace: newText = newText + ' ' newText = _expand_after_special_chars(newText) newText = newText.replace("%", "%%") # Escape any format chars. Text(newText).execute() else: # Failed to get text from clipboard. Key('c-v').execute() # Restore cut out text. _set_clipboard_text(saveText)
def expand_count(n): """Formats n words to the left of the cursor by adding whitespace in certain positions. Note that word count differs between editors and programming languages. The examples are all from Eclipse/Python. Example, with to compact code: "result=(width1+width2)/2 'expand 9' " => "result = (width1 + width2) / 2" """ saveText = _get_clipboard_text() cutText = _select_and_cut_text(n) if cutText: endSpace = cutText.endswith(' ') cutText = _expand_after_special_chars(cutText) reg = re.compile( r'([a-zA-Z0-9_\"\'\)][=\+\-\*/\%]|[=\+\-\*/\%][a-zA-Z0-9_\"\'\(])') hit = reg.search(cutText) count = 0 while hit and count < 10: cutText = cutText[:hit.start() + 1] + ' ' + \ cutText[hit.end() - 1:] hit = reg.search(cutText) count += 1 newText = cutText if endSpace: newText = newText + ' ' newText = newText.replace("%", "%%") # Escape any format chars. Text(newText).execute() else: # Failed to get text from clipboard. Key('c-v').execute() # Restore cut out text. _set_clipboard_text(saveText)
def _execute(self, data=None): output = control.nexus().temp Text(output).execute() if output: Key(self.action_if_text).execute() else: Key(self.action_if_no_text).execute() return True
def squash_text(text): """Formats dictated text with whitespace removed. Example: "'squash my new variable'" => "mynewvariable". """ newText = format_squash(text) Text("%(text)s").execute({"text": newText})
def snake_case_text(text): """Formats dictated text to snake case. Example: "'snake case my new variable'" => "my_new_variable". """ newText = format_snake_case(text) Text("%(text)s").execute({"text": newText})
def pascal_case_text(text): """Formats dictated text to pascal case. Example: "'pascal case my new variable'" => "MyNewVariable". """ newText = format_pascal_case(text) Text("%(text)s").execute({"text": newText})
def camel_case_text(text): """Formats dictated text to camel case. Example: "'camel case my new variable'" => "myNewVariable". """ newText = format_camel_case(text) Text("%(text)s").execute({"text": newText})
def handle_word(text): #words = map(list, text) #print text words = str(text).split() print 'word (', words, ')' if len(words) > 0: Text(words[0]).execute() if len(words) > 1: Mimic(' '.join(words[1:])).execute()
def lowercase_text(text): """Formats dictated text to lower case. Example: "'lower case John Johnson'" => "john johnson". """ newText = format_lower_case(text) Text("%(text)s").execute({"text": newText})
def uppercase_text(text): """Formats dictated text to upper case. Example: "'upper case my new variable'" => "MY NEW VARIABLE". """ newText = format_upper_case(text) Text("%(text)s").execute({"text": newText})
class PrimitiveCommand(MappingRule): mapping = { 'vim scratch': Key('X'), 'vim chuck': Key('x'), 'vim undo': Key('u'), 'plap': Key('P'), 'plop': Key('p'), 'ditto': Text('.'), 'ripple': 'macro', }
class PrimitiveCommand(MappingRule): mapping = { 'flax': Key('X'), 'nix': Key('x'), 'undo': Key('u'), 'pesto': Key('P'), 'post': Key('p'), 'ditto': Text('.'), 'ripple': 'macro', "visual": Key("v"), "visual line": Key("s-v"), "visual block": Key("c-v"), 'dell': Key('d'), 'yank': Key('y'), "dello": Text("daw"), "cello": Text("caw") #"indent left": Key("<"), #"indent right": Key(">") }
def value(self, node): # This file is imported by "_all.py" and needs to return something that has an "execute()" function. # But remote mouse actions don't have an "execute()" function, and if we directly perform mouse actions here, # they will get executed before the rest of the actions. # To support our mouse grid modes, we want the mouse action to happen at the end of the sequence, so the # user can move the mouse cursor first then click the mouse after the move. # So we'll do nothing in "value()", but we'll get "_all.py" to call "possibleMouseAction()" at the end of # the sequence. #print "MouseButtonRule is saving the words", node.words(), "to check for mouse button actions later." #self.words = node.words() return Text()
class KeyInsertion(MappingRule): mapping = { '<text>': Text('%(text)s'), #catch-all for text 'ace [<count>]': Key('space:%(count)d'), 'tab [<count>]': Key('tab:%(count)d'), 'slap [<count>]': Key('enter:%(count)d'), 'chuck [<count>]': Key('del:%(count)d'), 'scratch [<count>]': Key('backspace:%(count)d'), 'ack': Key('escape'), } extras = [Dictation("text"), ruleDigitalInteger[3]] defaults = {'count': 1}
def handle_word(text): words = str(text).split() print 'word (', words, ')' if len(words) > 0: Text(words[0]).execute() global lastFormatRuleWords global lastFormatRuleLength lastFormatRuleWords = words[0:1] lastFormatRuleLength = len(words[0]) if len(words) > 1: Mimic(' '.join(words[1:])).execute()
def value(self, node): words = node.words() print "format rule:", words uppercase = words[0] == 'upper' lowercase = words[0] != 'natural' if lowercase: words = [word.lower() for word in words] if uppercase: words = [word.upper() for word in words] words = [word.split('\\', 1)[0].replace('-', '') for word in words] if words[0].lower() in ('upper', 'natural'): del words[0] bomb = None if 'bomb' in words: bomb_point = words.index('bomb') if bomb_point + 1 < len(words): bomb = words[bomb_point + 1:] words = words[:bomb_point] function = getattr(tformat, 'format_%s' % words[0].lower()) formatted = function(words[1:]) global lastFormatRuleWords lastFormatRuleWords = words[1:] global lastFormatRuleLength lastFormatRuleLength = len(formatted) # empty formatted causes problems here print " ->", formatted if bomb != None: return Text(formatted) + Mimic(' '.join(bomb)) else: return Text(formatted)
def value(self, node): delegates = node.children[0].children[0].children value = delegates[-1].value() prefix = '' if delegates[0].value() is not None: prefix += str(delegates[0].value()) if delegates[1].value() is not None: # Hack for macros reg = delegates[1].value()[1] if value == 'macro': prefix += '@' + reg value = None else: prefix += "'" + reg if prefix: if value is not None: value = Text(prefix) + value else: value = Text(prefix) # TODO: ugly hack; should fix the grammar or generalize. if 'chaos' in zip(*node.results)[0]: return [('c', value), ('i', (NoAction(), ) * 2)] else: return [('c', value)]