Herpderp, CRLF
This commit is contained in:
parent
3390a4b8d7
commit
0a710ab18a
@ -1,77 +1,77 @@
|
|||||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
#
|
#
|
||||||
# This file is part of qutebrowser.
|
# This file is part of qutebrowser.
|
||||||
#
|
#
|
||||||
# qutebrowser is free software: you can redistribute it and/or modify
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# qutebrowser is distributed in the hope that it will be useful,
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""Advanced keyparsers."""
|
"""Advanced keyparsers."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from qutebrowser.keyinput._basekeyparser import BaseKeyParser
|
from qutebrowser.keyinput._basekeyparser import BaseKeyParser
|
||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
|
|
||||||
from qutebrowser.commands.managers import (CommandManager, ArgumentCountError,
|
from qutebrowser.commands.managers import (CommandManager, ArgumentCountError,
|
||||||
NoSuchCommandError)
|
NoSuchCommandError)
|
||||||
|
|
||||||
|
|
||||||
class CommandKeyParser(BaseKeyParser):
|
class CommandKeyParser(BaseKeyParser):
|
||||||
|
|
||||||
"""KeyChainParser for command bindings.
|
"""KeyChainParser for command bindings.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
commandmanager: CommandManager instance.
|
commandmanager: CommandManager instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parent=None, supports_count=None,
|
def __init__(self, parent=None, supports_count=None,
|
||||||
supports_chains=False):
|
supports_chains=False):
|
||||||
super().__init__(parent, supports_count, supports_chains)
|
super().__init__(parent, supports_count, supports_chains)
|
||||||
self.commandmanager = CommandManager()
|
self.commandmanager = CommandManager()
|
||||||
|
|
||||||
def _run_or_fill(self, cmdstr, count=None, ignore_exc=True):
|
def _run_or_fill(self, cmdstr, count=None, ignore_exc=True):
|
||||||
"""Run the command in cmdstr or fill the statusbar if args missing.
|
"""Run the command in cmdstr or fill the statusbar if args missing.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmdstr: The command string.
|
cmdstr: The command string.
|
||||||
count: Optional command count.
|
count: Optional command count.
|
||||||
ignore_exc: Ignore exceptions.
|
ignore_exc: Ignore exceptions.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.commandmanager.run(cmdstr, count=count, ignore_exc=ignore_exc)
|
self.commandmanager.run(cmdstr, count=count, ignore_exc=ignore_exc)
|
||||||
except NoSuchCommandError:
|
except NoSuchCommandError:
|
||||||
pass
|
pass
|
||||||
except ArgumentCountError:
|
except ArgumentCountError:
|
||||||
logging.debug('Filling statusbar with partial command {}'.format(
|
logging.debug('Filling statusbar with partial command {}'.format(
|
||||||
cmdstr))
|
cmdstr))
|
||||||
message.set_cmd_text(':{} '.format(cmdstr))
|
message.set_cmd_text(':{} '.format(cmdstr))
|
||||||
|
|
||||||
def execute(self, cmdstr, _keytype, count=None):
|
def execute(self, cmdstr, _keytype, count=None):
|
||||||
self._run_or_fill(cmdstr, count, ignore_exc=False)
|
self._run_or_fill(cmdstr, count, ignore_exc=False)
|
||||||
|
|
||||||
|
|
||||||
class PassthroughKeyParser(CommandKeyParser):
|
class PassthroughKeyParser(CommandKeyParser):
|
||||||
|
|
||||||
"""KeyChainParser which passes through normal keys.
|
"""KeyChainParser which passes through normal keys.
|
||||||
|
|
||||||
Used for insert/passthrough modes.
|
Used for insert/passthrough modes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, confsect, parent=None):
|
def __init__(self, confsect, parent=None):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
confsect: The config section to use.
|
confsect: The config section to use.
|
||||||
"""
|
"""
|
||||||
super().__init__(parent, supports_chains=False)
|
super().__init__(parent, supports_chains=False)
|
||||||
self.read_config(confsect)
|
self.read_config(confsect)
|
||||||
|
@ -1,90 +1,90 @@
|
|||||||
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
#
|
#
|
||||||
# This file is part of qutebrowser.
|
# This file is part of qutebrowser.
|
||||||
#
|
#
|
||||||
# qutebrowser is free software: you can redistribute it and/or modify
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# qutebrowser is distributed in the hope that it will be useful,
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""KeyChainParser for "hint" and "normal" modes.
|
"""KeyChainParser for "hint" and "normal" modes.
|
||||||
|
|
||||||
Module attributes:
|
Module attributes:
|
||||||
STARTCHARS: Possible chars for starting a commandline input.
|
STARTCHARS: Possible chars for starting a commandline input.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal
|
||||||
|
|
||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
from qutebrowser.keyinput.keyparser import CommandKeyParser
|
from qutebrowser.keyinput.keyparser import CommandKeyParser
|
||||||
|
|
||||||
|
|
||||||
STARTCHARS = ":/?"
|
STARTCHARS = ":/?"
|
||||||
|
|
||||||
|
|
||||||
class NormalKeyParser(CommandKeyParser):
|
class NormalKeyParser(CommandKeyParser):
|
||||||
|
|
||||||
"""KeyParser for normalmode with added STARTCHARS detection."""
|
"""KeyParser for normalmode with added STARTCHARS detection."""
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent, supports_count=True, supports_chains=True)
|
super().__init__(parent, supports_count=True, supports_chains=True)
|
||||||
self.read_config('keybind')
|
self.read_config('keybind')
|
||||||
|
|
||||||
def _handle_single_key(self, e):
|
def _handle_single_key(self, e):
|
||||||
"""Override _handle_single_key to abort if the key is a startchar.
|
"""Override _handle_single_key to abort if the key is a startchar.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
e: the KeyPressEvent from Qt.
|
e: the KeyPressEvent from Qt.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if event has been handled, False otherwise.
|
True if event has been handled, False otherwise.
|
||||||
"""
|
"""
|
||||||
txt = e.text().strip()
|
txt = e.text().strip()
|
||||||
if not self._keystring and any(txt == c for c in STARTCHARS):
|
if not self._keystring and any(txt == c for c in STARTCHARS):
|
||||||
message.set_cmd_text(txt)
|
message.set_cmd_text(txt)
|
||||||
return True
|
return True
|
||||||
return super()._handle_single_key(e)
|
return super()._handle_single_key(e)
|
||||||
|
|
||||||
|
|
||||||
class HintKeyParser(CommandKeyParser):
|
class HintKeyParser(CommandKeyParser):
|
||||||
|
|
||||||
"""KeyChainParser for hints.
|
"""KeyChainParser for hints.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
fire_hint: When a hint keybinding was completed.
|
fire_hint: When a hint keybinding was completed.
|
||||||
Arg: the keystring/hint string pressed.
|
Arg: the keystring/hint string pressed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fire_hint = pyqtSignal(str)
|
fire_hint = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent, supports_count=False, supports_chains=True)
|
super().__init__(parent, supports_count=False, supports_chains=True)
|
||||||
self.read_config('keybind.hint')
|
self.read_config('keybind.hint')
|
||||||
|
|
||||||
def execute(self, cmdstr, keytype, count=None):
|
def execute(self, cmdstr, keytype, count=None):
|
||||||
"""Handle a completed keychain.
|
"""Handle a completed keychain.
|
||||||
|
|
||||||
Emit:
|
Emit:
|
||||||
fire_hint: Emitted if keytype is TYPE_CHAIN
|
fire_hint: Emitted if keytype is TYPE_CHAIN
|
||||||
"""
|
"""
|
||||||
if keytype == self.TYPE_CHAIN:
|
if keytype == self.TYPE_CHAIN:
|
||||||
self.fire_hint.emit(cmdstr)
|
self.fire_hint.emit(cmdstr)
|
||||||
else:
|
else:
|
||||||
# execute as command
|
# execute as command
|
||||||
super().execute(cmdstr, keytype, count)
|
super().execute(cmdstr, keytype, count)
|
||||||
|
|
||||||
def on_hint_strings_updated(self, strings):
|
def on_hint_strings_updated(self, strings):
|
||||||
"""Handler for HintManager's hint_strings_updated.
|
"""Handler for HintManager's hint_strings_updated.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
strings: A list of hint strings.
|
strings: A list of hint strings.
|
||||||
"""
|
"""
|
||||||
self.bindings = {s: s for s in strings}
|
self.bindings = {s: s for s in strings}
|
||||||
|
Loading…
Reference in New Issue
Block a user