예제 #1
0
파일: markdown.py 프로젝트: zilch42/Caster
class Markdown(MergeRule):
    pronunciation = "mark down"

    mapping = {
        "heading [<num>] [<dict>]":
        R(Store() + Function(lambda num, dict: Text(
            ("#" * num) + " " + str(dict).capitalize()).execute()) +
          Retrieve() + Key("enter")),
        "table row <n>":
        R(Function(lambda n: Text("|" * (n - 1)).execute()) + Key("home")),
        "table (break | split) <n>":
        R(
            Function(lambda n: Text("---|" * (n - 1) + "---").execute()) +
            Key("enter")),
        "insert <element>":
        R(Store() + Key("%(element)s") + Retrieve(action_if_text="c-right")),
        "insert header":
        R(Text("---\nauthor: \ntitle: \n---\n")),
    }
    extras = [
        Dictation("dict"),
        ShortIntegerRef("n", 1, 12),
        ShortIntegerRef("num", 1, 7),
        Choice(
            "element", {
                "list": "asterisk, space",
                "numbered list": "one, dot, space",
                "[block] quote": "rangle, space",
                "link": "lbracket, rbracket, lparen, rparen, left:3",
                "image":
                "exclamation, lbracket, rbracket, lparen, rparen, left:3",
                "reference": "lbracket, rbracket, left, at",
                "equation": "dollar, dollar, enter:2, dollar, dollar, up",
                "math": "dollar, dollar, left",
                "(italics | italic text)": "underscore:2, left",
                "bold [text]": "asterisk:4, left:2",
                "strike through [text]": "tilde:4, left:2",
                "horizontal rule": "asterisk, asterisk, asterisk, enter",
                "R code":
                "backtick:3, lbrace, r, rbrace, enter:2, backtick:3, up",
                "in line code": "backtick:2, left",
                "code [block]": "backtick:6, left:3, enter:2, up",
            }),
    ]
    defaults = {
        "num": 1,
        "dict": "",
    }
예제 #2
0
class ChromeRule(MappingRule):
    _mapping = {
        browser_shared.PREVIOUS_TAB_N_TIMES:
        R(Key("cs-tab")) * Repeat(extra="n"),
        browser_shared.SWITCH_TO_TAB_N:
        R(Key("c-%(m)s%(nth)s")),
        browser_shared.SWITCH_TO_LAST_TAB:
        R(Key("c-9")),
        browser_shared.SWITCH_TO_SECOND_TO_LAST_TAB:
        R(Key("c-9, cs-tab")),
        "switch focus [<n>]":
        R(Key("f6/20")) * Repeat(extra="n"),
        browser_shared.TOGGLE_BOOKMARK_TOOLBAR:
        R(Key("cs-b")),
        "switch user":
        R(Key("cs-m")),
        "focus notification":
        R(Key("a-n")),
        "allow notification":
        R(Key("as-a")),
        "deny notification":
        R(Key("as-a")),
        "google that":
        R(Store(remove_cr=True) + Key("c-t") + Retrieve() + Key("enter")),
        "wikipedia that":
        R(
            Store(space="+", remove_cr=True) + Key("c-t") +
            Text("https://en.wikipedia.org/w/index.php?search=") + Retrieve() +
            Key("enter")),
        browser_shared.SHOW_EXTENSIONS:
        R(Key("a-f/20, l, e/15, enter")),
        "more tools":
        R(Key("a-f/5, l")),
    }
    mapping = BrowserSharedCommands.merge_dictionaries(
        _mapping, BrowserSharedCommands.chromeAndFirefoxMapping)
    extras = browser_shared.get_extras()
    defaults = browser_shared.get_defaults()
예제 #3
0
class Python(MergeRule):

    mapping = {
        SymbolSpecs.IF:
            R(Key("i,f,space,colon,left")),
        SymbolSpecs.ELSE:
            R(Text("else:") + Key("enter")),
        # (no switch in Python)
        SymbolSpecs.BREAK:
            R(Text("break")),
        SymbolSpecs.FOR_EACH_LOOP:
            R(Store() + Text("for  in :") + Key("left:5") +
              Retrieve(action_if_text="right:5")),
        SymbolSpecs.FOR_LOOP:
            R(Store() + Text("for i in range(0, ):") + Key("left:2") +
              Retrieve(action_if_text="right:2")),
        SymbolSpecs.WHILE_LOOP:
            R(Store() + Text("while :") + Key("left") + Retrieve(action_if_text="right")),
        # (no do-while in Python)
        SymbolSpecs.TO_INTEGER:
            R(Store() + Text("int()") + Key("left") + Retrieve(action_if_text="right")),
        SymbolSpecs.TO_FLOAT:
            R(Store() + Text("float()") + Key("left") + Retrieve(action_if_text="right")),
        SymbolSpecs.TO_STRING:
            R(Store() + Text("str()") + Key("left") + Retrieve(action_if_text="right")),
        SymbolSpecs.AND:
            R(Text(" and ")),
        SymbolSpecs.OR:
            R(Text(" or ")),
        SymbolSpecs.NOT:
            R(Text("!")),
        SymbolSpecs.SYSOUT:
            R(Store() + Text("print()") + Key("left") + Retrieve(action_if_text="right")),
        SymbolSpecs.IMPORT:
            R(Text("import ")),
        SymbolSpecs.FUNCTION:
            R(Store() + Text("def ():") + Key("left:3") +
              Retrieve(action_if_text="right:3")),
        SymbolSpecs.CLASS:
            R(Store() + Text("class :") + Key("left") + Retrieve(action_if_text="right")),
        SymbolSpecs.COMMENT:
            R(Store() + Text("#") + Key("space") + Retrieve(action_if_text="right")),
        SymbolSpecs.LONG_COMMENT:
            R(Store() + Text("''''''") + Key("left:3") +
              Retrieve(action_if_text="right:3")),
        SymbolSpecs.NULL:
            R(Text("None")),
        SymbolSpecs.RETURN:
            R(Text("return ")),
        SymbolSpecs.TRUE:
            R(Text("True")),
        SymbolSpecs.FALSE:
            R(Text("False")),

        # Python specific
        "sue iffae":
            R(Text("if ")),
        "sue shells":
            R(Text("else ")),
        "from":
            R(Text("from ")),
        "self":
            R(Text("self")),
        "long not":
            R(Text(" not ")),
        "it are in":
            R(Text(" in ")),
        "shell iffae | LFA":
            R(Key("e,l,i,f,space,colon,left")),
        "convert to character":
            R(Store() + Text("chr()") + Key("left") + Retrieve(action_if_text="right")),
        "length of":
            R(Store() + Text("len()") + Key("left") + Retrieve(action_if_text="right")),
        "global":
            R(Text("global ")),
        "make assertion":
            R(Text("assert ")),
        "list (comprehension | comp)":
            R(Text("[x for x in TOKEN if TOKEN]")),
        "[dot] (pie | pi)":
            R(Text(".py")),
        "toml":
            R(Text("toml")),
        "jason":
            R(Text("toml")),
        "identity is":
            R(Text(" is ")),
        "yield":
            R(Text("yield ")),

        # Essentially an improved version of the try catch command above
        # probably a better option than this is to use snippets with tab stops
        # VS code has the extension Python-snippets. these are activated by
        # going into the command pallet (cs-p) and typing in "insert snippet"
        # then press enter and then you have choices of snippets show up in the drop-down list.
        # you can also make your own snippets.
        "try [<exception>]":
            R(
                Text("try : ") + Pause("10") + Key("enter/2") +
                Text("except %(exception)s:") + Pause("10") + Key("enter/2")),
        "try [<exception>] as":
            R(
                Text("try :") + Pause("10") + Key("enter/2") +
                Text("except %(exception)s as :") + Pause("10") + Key("enter/2")),

        # class and class methods
        "sub class":
            R(Store() + Text("class ():") + Key("left:3") +
              Retrieve(action_if_text="right:3")),
        "dunder":
            R(Store() + Text("____()") + Key("left:4") +
              Retrieve(action_if_text="right:4")),
        "init":
            R(Store() + Text("__init__()") + Key("left") +
              Retrieve(action_if_text="right")),
        "meth [<binary_meth>]":
            R(Text("__%(binary_meth)s__(self, other):")),
        "meth [<unary_meth>]":
            R(Text("__%(unary_meth)s__(self):")),
    }

    extras = [
        Dictation("text"),
        Choice("unary_meth", {
            "reper": "reper",
            "stir": "str",
            "len": "len",
        }),
        Choice("binary_meth", {
            "add": "add",
            "subtract": "sub",
        }),
        Choice(
            "exception", {
                "exception": "Exception",
                "stop iteration": "StopIteration",
                "system exit": "SystemExit",
                "standard": "StandardError",
                "arithmetic": "ArithmeticError",
                "overflow": "OverflowError",
                "floating point": "FloatingPointError",
                "zero division": "ZeroDivisionError",
                "assertion": "AssertionError",
                "EOF": "EOFError",
                "import": "ImportError",
                "keyboard interrupt": "KeyboardInterrupt",
                "lookup": "LookupError",
                "index": "IndexError",
                "key": "KeyError",
                "name": "NameError",
                "unbound local": "UnboundLocalError",
                "environment": "EnvironmentError",
                "IO": "IOError",
                "OS": "OSError",
                "syntax": "SyntaxError",
                "system exit": "SystemExit",
                "type": "TypeError",
                "value": "ValueError",
                "run time": "RuntimeError",
                "not implemented": "NotImplementedError",
            })
    ]
    defaults = {"unary_meth": "", "binary_meth": "", "exception": ""}
예제 #4
0
파일: gitter.py 프로젝트: lahwran/Caster
class GitterRule(MappingRule):
    mapping = {
        "bold":
        R(Store() + Text("****") + Key("left:2") +
          Retrieve(action_if_text="right:2")),
        "emphasize":
        R(Store() + Text("**") + Key("left") +
          Retrieve(action_if_text="right")),
        "strike through":
        R(Store() + Text("~~~~") + Key("left:2") +
          Retrieve(action_if_text="right:2")),
        "latex":
        R(Store() + Text("$$$$") + Key("left:2") +
          Retrieve(action_if_text="right:2")),
        "<header_size> header":
        R(Store() + Text("%(header_size)s ") +
          Retrieve(action_if_text="s-enter")),
        "insert item":
        R(Store() + Text("*") + Key("space") +
          Retrieve(action_if_text="s-enter")),
        "block quote":
        R(Store() + Text(">") + Key("space") +
          Retrieve(action_if_text="s-enter")),
        "mention":
        R(Store() + Text("@") + Retrieve(action_if_text="right, space")),
        "insert link":
        R(Store() + Text("[]()") + Key("left:3") +
          Retrieve(action_if_text="right:2")),
        "insert image":
        R(Store() + Text("![]()") + Key("left:3") +
          Retrieve(action_if_text="right:2")),
        "insert code":
        R(Store() + Text("``") + Key("left") +
          Retrieve(action_if_text="right")),
        "formatted code":
        R(Store() + Text("``````") + Pause("0.5") +
          Key("left:3,s-enter:2,up") + Retrieve()),
    }
    extras = [
        Choice("header_size", {
            "small": "###",
            "medium": "##",
            "large": "#",
        }),
    ]
    Defaults = {}
예제 #5
0
파일: firefox.py 프로젝트: pimp22/Caster
class FirefoxRule(MappingRule):
    mapping = {
        "(new window|win new)":
            R(Key("c-n")),
        "(new incognito window | incognito)":
            R(Key("cs-n")),
        "new tab [<n>]|tab new [<n>]":
            R(Key("c-t") * Repeat(extra="n")),
        "reopen tab [<n>]|tab reopen [<n>]":
            R(Key("cs-t")) * Repeat(extra="n"),
        "close tab [<n>]|tab close [<n>]":
            R(Key("c-w")) * Repeat(extra='n'),
        "win close|close all tabs":
            R(Key("cs-w")),
        "(next|forward) tab [<n>]|tab (right|sauce) [<n>]":
            R(Key("c-tab")) * Repeat(extra="n"),
        "(back|prev|prior|previous) tab [<n>]|tab (left|lease) [<n>]":
        # control shift tab doesn't work and this appears to be an undocumented workaround
            R(Key("c-tab/30")) * Repeat(extra="n"),
        "new tab that":
            R(Mouse("middle") + Pause("20") + Key("c-tab")),
        "go (back|prev|prior|previous) [<n>]":
            R(Key("a-left/20")) * Repeat(extra="n"),
        "go (next|forward) [<n>]":
            R(Key("a-right/20")) * Repeat(extra="n"),
        "zoom in [<n>]":
            R(Key("c-plus/20")) * Repeat(extra="n"),
        "zoom out [<n>]":
            R(Key("c-minus/20")) * Repeat(extra="n"),
        "zoom reset":
            R(Key("c-0")),
        "(hard refresh|super refresh)":
            R(Key("c-f5")),
        "find (next|forward) [match] [<n>]": 
            R(Key("c-g/20")) * Repeat(extra="n"),
        # requires an extension in some browsers such as chrome
        "[toggle] caret browsing":
            R(Key("f7")),
        "[go] home [page]":
            R(Key("a-home")),
        "[show] history":
            R(Key("c-h")),
        "address bar":
            R(Key("c-l")),
        "[show] downloads":
            R(Key("c-j")),
        "[add] bookmark":
            R(Key("c-d")),
        "bookmark all [tabs]":
            R(Key("cs-d")),
       "[show] bookmarks":
            R(Key("cs-o")),
        "[toggle] full screen":
            R(Key("f11")),
        "(show|view) page source":
            R(Key("c-u")),
        "resume":
            R(Key("f8")),
        "step over":
            R(Key("f10")),
        "step into":
            R(Key("f11")),
        "step out":
            R(Key("s-f11")),
        "(duplicate tab|tab duple)":
            R(Key("a-d,a-c,c-t/15,c-v/15, enter")),
        "(duplicate window|win duple)":
            R(Key("a-d,a-c,c-n/15,c-v/15, enter")),
        "[show] (menu | three dots)":
            R(Key("a-f")),
        "[show] settings":
            R(Key("a-f/5, s")),
        "(clear history|clear browsing data)":
            R(Key("cs-del")),
        "[show] developer tools":
            R(Key("cs-i")),
        "checkout [this] pull request [locally]":
            R(Function(github_automation.github_checkoutupdate_pull_request, new=True)),
        "update [this] pull request [locally]":
            R(Function(github_automation.github_checkoutupdate_pull_request, new=False)),
        "IRC identify":
            R(Text("/msg NickServ identify PASSWORD")),
        "[toggle] bookmark bar":
            R(Key("c-b")),
        "[show] (extensions|plugins)":
            R(Key("a-a, l, e/15, enter")),
        "google that":
            R(Store(remove_cr=True) + Key("c-t") + Retrieve() + Key("enter")),
        "wikipedia that":
            R(Store(space="+", remove_cr=True) + Key("c-t") + Text(
                "https://en.wikipedia.org/w/index.php?search=") + Retrieve() + Key("enter")),
    }
    extras = [
        Choice("nth", {
                "first": "1",
                "second": "2",
                "third": "3",
                "fourth": "4",
                "fifth": "5",
                "sixth": "6",
                "seventh": "7",
                "eighth": "8",
            }),
        IntegerRefST("n", 1, 100),
        IntegerRefST("m", 1, 10)
    ]
    defaults = {"n": 1, "m":"", "nth": ""}
예제 #6
0
파일: rstudio.py 프로젝트: zilch42/Caster
class RStudioRule(MappingRule):
    mapping = {
        "new file":
        R(Key("cs-n")),
        "open file":
        R(Key("c-o")),
        "open recent project":
        R(Key("a-f, j")),
        "open project":
        R(Key("a-f, n, enter")),
        "save all":
        R(Key("ac-s")),
        "select all":
        R(Key("c-a")),
        "find":
        R(Key("c-f")),
        "[go to] line <ln1>":
        R(Key("as-g") + Pause("10") + Text("%(ln1)s") + Key("enter")),
        "<action> [line] <ln1> [by <ln2>]":
        R(
            Function(navigation.action_lines,
                     go_to_line="as-g/10",
                     select_line_down="s-down",
                     wait="/3",
                     upon_arrival="home, ")),
        "focus console":
        R(Key("c-2")),
        "focus main":
        R(Key("c-1")),
        "next tab":
        R(Key("c-f12")),
        "first tab":
        R(Key("cs-f11")),
        "previous tab":
        R(Key("c-f11")),
        "last tab":
        R(Key("cs-f12")),
        "close tab":
        R(Key("c-w")),
        "run line":
        R(Key("c-enter")),
        "run document":
        R(Key("ac-r")),
        "comment (line | selected)":
        R(Key("cs-c")),
        "next plot":
        R(Key("ac-f12")),
        "previous plot":
        R(Key("ac-f11")),
        "(help | document) that":
        R(Store() + Key("c-2, question") + Retrieve() + Key("enter, c-3")),
        "glimpse that":
        R(Store() + Key("c-2") + Retrieve() +
          Key("space, percent, rangle, percent") + Text(" glimpse()") +
          Key("enter/50, c-1")),
        "vee table that":
        R(Store() + Key("c-2") + Text("library(vtable)") + Key("enter/50") +
          Retrieve() + Key("space, percent, rangle, percent") +
          Text(" vtable()") + Key("enter/50, c-1")),
    }
    extras = [
        ShortIntegerRef("ln1", 1, 10000),
        ShortIntegerRef("ln2", 1, 10000),
        Choice("action", navigation.actions),
    ]
    defaults = {"ln2": ""}
예제 #7
0
파일: sublime.py 프로젝트: zilch42/Caster
class SublimeRule(MappingRule):
    mapping = {
        "new file":
        R(Key("c-n")),
        "new window":
        R(Key("cs-n")),
        "open file":
        R(Key("c-o")),
        "open folder":
        R(Key("f10, f, down:2, enter")),
        "open recent":
        R(Key("f10, f, down:3, enter")),
        "save as":
        R(Key("cs-s")),
        #
        "comment line":
        R(Key("c-slash")),
        "comment block":
        R(Key("cs-slash")),
        "outdent lines":
        R(Key("c-lbracket")),
        "join lines":
        R(Key("c-j")),
        "match bracket":
        R(Key("c-m")),
        #
        "(select | sell) all":
        R(Key("c-a")),
        "(select | sell) scope [<n2>]":
        R(Key("cs-space") * Repeat(extra="n2")),
        "(select | sell) brackets [<n2>]":
        R(Key("cs-m") * Repeat(extra="n2")),
        "(select | sell) indent":
        R(Key("cs-j")),
        #
        "find":
        R(Key("c-f")),
        "get all":
        R(Key("a-enter")),
        "replace":
        R(Key("c-h")),
        "replace all":
        R(Key("ca-enter")),
        "paste from history":
        R(Key("c-k,c-v")),
        "edit lines":
        R(Key("cs-l")),
        "edit next [<n3>]":
        R(Key("c-d/10")) * Repeat(extra="n3"),
        "edit only next [<n3>]":
        R(Key("c-k,c-d/10")) * Repeat(extra="n3"),
        "edit up [<n3>]":
        R(Key("ac-up")) * Repeat(extra="n3"),
        "edit down [<n3>]":
        R(Key("ac-down")) * Repeat(extra="n3"),
        "edit all":
        R(Key("a-f3")),
        #
        "transform upper":
        R(Key("c-k, c-u")),
        "transform lower":
        R(Key("c-k, c-l")),
        #
        "line <ln1>":
        R(Key("c-g/10") + Text("%(ln1)s") + Key("enter")),
        "<action> [line] <ln1> [by <ln2>]":
        R(Function(navigation.action_lines)),
        "[move] line down [<n3>]":
        R(Key("cs-down") * Repeat(extra='n3')),
        "[move] line up [<n3>]":
        R(Key("cs-up") * Repeat(extra='n3')),
        #
        "go to file":
        R(Key("c-p")),
        "go to <dict> [<filetype>]":
        R(Key("c-p") + Text("%(dict)s" + "%(filetype)s") + Key("enter")),
        "file back [<n2>]":
        R(Key("c-p") + Key("down") * Repeat(extra="n2") + Key("enter")),
        #
        "go to word":
        R(Key("c-semicolon")),
        "go to symbol":
        R(Key("c-r")),
        "go to [symbol in] project":
        R(Key("cs-r")),
        "go to that":
        R(Store() + Key("cs-r") + Retrieve() + Key("enter")),
        "find that in project":
        R(Store() + Key("cs-f") + Retrieve() + Key("enter")),
        "find that":
        R(Store() + Key("c-f") + Retrieve() + Key("enter")),
        "command pallette":
        R(Key("cs-p")),
        #
        "go back [<n2>]":
        R(Key("a-minus") * Repeat(extra="n2")),
        "go forward [<n2>]":
        R(Key("a-plus") * Repeat(extra="n2")),
        "next modification":
        R(Key("c-dot")),
        "previous modification":
        R(Key("c-comma")),
        #
        "fold":
        R(Key("cs-lbracket")),
        "unfold":
        R(Key("cs-rbracket")),
        "unfold all":
        R(Key("c-k, c-j")),
        "fold [level] <n2>":
        R(Key("c-k, c-%(n2)s")),
        #
        "full screen":
        R(Key("f11")),
        "toggle side bar":
        R(Key("c-k, c-b")),
        "show key bindings":
        R(Key("f10, p, right, k")),
        "show at center":
        R(Key("c-k,c-c")),
        "zoom in [<n2>]":
        R(Key("c-equal") * Repeat(extra="n2")),
        "zoom out [<n2>]":
        R(Key("c-minus") * Repeat(extra="n2")),
        #
        "(set | add) bookmark":
        R(Key("c-f2")),
        "next bookmark":
        R(Key("f2")),
        "previous bookmark":
        R(Key("s-f2")),
        "clear bookmarks":
        R(Key("cs-f2")),
        #
        "set mark":
        R(Key("c-k,c-space")),
        "select mark":
        R(Key("c-k,c-a")),
        "swap with mark":
        R(Key("c-k,c-x")),
        "delete mark":
        R(Key("c-k,c-w")),
        #
        "build it":
        R(Key("c-b")),
        "build with":
        R(Key("cs-b")),
        "build <nth>":
        R(Key("c-s,a-%(nth)s,c-b")),
        "build [<nth>] last":
        R(Key("c-s,a-1") + Key("c-pageup") * Repeat(extra="nth") + Key("c-b")),
        #
        "record macro":
        R(Key("c-q")),
        "play [back] macro [<n3>]":
        R(Key("cs-q/10")),
        "(new | create) snippet":
        R(Key("ac-n")),
        #
        "close tab":
        R(Key("c-w")),
        "next tab":
        R(Key("c-pgdown")),
        "previous tab":
        R(Key("c-pgup")),
        "<nth> tab":
        R(Key("a-%(nth)s")),
        "[<nth>] last tab":
        R(Key("a-1") + Key("c-pageup") * Repeat(extra="nth")),
        "column <cols>":
        R(Key("as-%(cols)s")),
        "focus <panel>":
        R(Key("c-%(panel)s")),
        "move <panel>":
        R(Key("cs-%(panel)s")),
        #
        "open terminal":
        R(Key("cs-t")),
        "open console":
        R(Key("c-`")),
    }
    extras = [
        Dictation("dict"),
        ShortIntegerRef("ln1", 1, 1000),
        ShortIntegerRef("ln2", 1, 1000),
        ShortIntegerRef("n2", 1, 9),
        ShortIntegerRef("n3", 1, 21),
        Choice("action", navigation.actions),
        Choice(
            "nth", {
                "first": "1",
                "second": "2",
                "third": "3",
                "fourth": "4",
                "fifth": "5",
                "sixth": "6",
                "seventh": "7",
                "eighth": "8",
                "ninth": "9",
            }),
        Choice("cols", {
            "one": "1",
            "two": "2",
            "three": "3",
            "grid": "5",
        }),
        Choice("panel", {
            "one": "1",
            "left": "1",
            "two": "2",
            "right": "2",
        }),
        Choice(
            "filetype", {
                "pie | python": "py",
                "mark [down]": "md",
                "tech": "tex",
                "tommel": "toml",
            }),
    ]
    defaults = {
        "ln2": "",
        "n2": 1,
        "n3": 1,
        "file type": "",
        "nth": "1",
    }