diff options
author | jakanakae-envangel <jakanakaevangeli@chiru.no> | 2018-03-08 18:06:54 +0100 |
---|---|---|
committer | jakanakae-envangel <jakanakaevangeli@chiru.no> | 2018-03-08 19:55:43 +0100 |
commit | 0cd73af691ff08d76eb1dd33f5bb45e9be2c250a (patch) | |
tree | fec5baec9388531c916614eea973f8ba9a5d5484 /qutebrowser/keyinput/modeparsers.py | |
parent | 63d23ca9df95f79b93a6bfe54eb8938ff0309611 (diff) | |
download | qutebrowser-0cd73af691ff08d76eb1dd33f5bb45e9be2c250a.tar.gz qutebrowser-0cd73af691ff08d76eb1dd33f5bb45e9be2c250a.zip |
keyinput: Merge keyparser into modeparsers
Diffstat (limited to 'qutebrowser/keyinput/modeparsers.py')
-rw-r--r-- | qutebrowser/keyinput/modeparsers.py | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index ce4cb71fa..1f76138e0 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -29,9 +29,9 @@ import enum from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QKeySequence -from qutebrowser.commands import cmdexc +from qutebrowser.commands import runners, cmdexc from qutebrowser.config import config -from qutebrowser.keyinput import keyparser, keyutils +from qutebrowser.keyinput import basekeyparser, keyutils from qutebrowser.utils import usertypes, log, message, objreg, utils @@ -39,7 +39,26 @@ STARTCHARS = ":/?" LastPress = enum.Enum('LastPress', ['none', 'filtertext', 'keystring']) -class NormalKeyParser(keyparser.CommandKeyParser): +class CommandKeyParser(basekeyparser.BaseKeyParser): + + """KeyChainParser for command bindings. + + Attributes: + _commandrunner: CommandRunner instance. + """ + + def __init__(self, win_id, parent=None, supports_count=None): + super().__init__(win_id, parent, supports_count) + self._commandrunner = runners.CommandRunner(win_id) + + def execute(self, cmdstr, count=None): + try: + self._commandrunner.run(cmdstr, count) + except cmdexc.Error as e: + message.error(str(e), stack=traceback.format_exc()) + + +class NormalKeyParser(CommandKeyParser): """KeyParser for normal mode with added STARTCHARS detection and more. @@ -127,7 +146,36 @@ class NormalKeyParser(keyparser.CommandKeyParser): pass -class PromptKeyParser(keyparser.CommandKeyParser): +class PassthroughKeyParser(CommandKeyParser): + + """KeyChainParser which passes through normal keys. + + Used for insert/passthrough modes. + + Attributes: + _mode: The mode this keyparser is for. + """ + + do_log = False + passthrough = True + + def __init__(self, win_id, mode, parent=None): + """Constructor. + + Args: + mode: The mode this keyparser is for. + parent: Qt parent. + warn: Whether to warn if an ignored key was bound. + """ + super().__init__(win_id, parent) + self._read_config(mode) + self._mode = mode + + def __repr__(self): + return utils.get_repr(self, mode=self._mode) + + +class PromptKeyParser(CommandKeyParser): """KeyParser for yes/no prompts.""" @@ -139,7 +187,7 @@ class PromptKeyParser(keyparser.CommandKeyParser): return utils.get_repr(self) -class HintKeyParser(keyparser.CommandKeyParser): +class HintKeyParser(CommandKeyParser): """KeyChainParser for hints. @@ -249,7 +297,7 @@ class HintKeyParser(keyparser.CommandKeyParser): hintmanager.handle_partial_key(keystr) -class CaretKeyParser(keyparser.CommandKeyParser): +class CaretKeyParser(CommandKeyParser): """KeyParser for caret mode.""" @@ -260,7 +308,7 @@ class CaretKeyParser(keyparser.CommandKeyParser): self._read_config('caret') -class RegisterKeyParser(keyparser.CommandKeyParser): +class RegisterKeyParser(CommandKeyParser): """KeyParser for modes that record a register key. |