コード例 #1
0
ファイル: style.py プロジェクト: ProtractorNinja/qutebrowser
def get_stylesheet(template_str):
    """Format a stylesheet based on a template.

    Args:
        template_str: The stylesheet template as string.

    Return:
        The formatted template as string.
    """
    colordict = ColorDict(config.section('colors'))
    fontdict = FontDict(config.section('fonts'))
    template = jinja2.Template(template_str)
    return template.render(color=colordict, font=fontdict)
コード例 #2
0
ファイル: style.py プロジェクト: xManusx/qutebrowser
def get_stylesheet(template_str):
    """Format a stylesheet based on a template.

    Args:
        template_str: The stylesheet template as string.

    Return:
        The formatted template as string.
    """
    colordict = ColorDict(config.section('colors'))
    template = jinja2.Template(template_str)
    return template.render(color=colordict, font=config.section('fonts'),
                           config=objreg.get('config'))
コード例 #3
0
def _get_cmd_completions(include_hidden, include_aliases, prefix=''):
    """Get a list of completions info for commands, sorted by name.

    Args:
        include_hidden: True to include commands annotated with hide=True.
        include_aliases: True to include command aliases.
        prefix: String to append to the command name.

    Return: A list of tuples of form (name, description, bindings).
    """
    assert cmdutils.cmd_dict
    cmdlist = []
    cmd_to_keys = objreg.get('key-config').get_reverse_bindings_for('normal')
    for obj in set(cmdutils.cmd_dict.values()):
        hide_debug = obj.debug and not objreg.get('args').debug
        hide_hidden = obj.hide and not include_hidden
        if not (hide_debug or hide_hidden or obj.deprecated):
            bindings = ', '.join(cmd_to_keys.get(obj.name, []))
            cmdlist.append((prefix + obj.name, obj.desc, bindings))

    if include_aliases:
        for name, cmd in config.section('aliases').items():
            bindings = ', '.join(cmd_to_keys.get(name, []))
            cmdlist.append((name, "Alias for '{}'".format(cmd), bindings))

    return cmdlist
コード例 #4
0
ファイル: keyconf.py プロジェクト: NoctuaNivalis/qutebrowser
    def _validate_command(self, line, modes=None):
        """Check if a given command is valid.

        Args:
            line: The commandline to validate.
            modes: A list of modes to validate the commands for, or None.
        """
        from qutebrowser.config import config
        if line == self.UNBOUND_COMMAND:
            return
        commands = line.split(';;')
        try:
            first_cmd = commands[0].split(maxsplit=1)[0].strip()
            cmd = cmdutils.cmd_dict[first_cmd]
            if cmd.no_cmd_split:
                commands = [line]
        except (KeyError, IndexError):
            pass

        for cmd in commands:
            if not cmd.strip():
                raise KeyConfigError("Got empty command (line: {!r})!".format(
                    line))
        commands = [c.split(maxsplit=1)[0].strip() for c in commands]
        for cmd in commands:
            aliases = config.section('aliases')
            if cmd in cmdutils.cmd_dict:
                cmdname = cmd
            elif cmd in aliases:
                cmdname = aliases[cmd].split(maxsplit=1)[0].strip()
            else:
                raise KeyConfigError("Invalid command '{}'!".format(cmd))
            cmd_obj = cmdutils.cmd_dict[cmdname]
            for m in modes or []:
                cmd_obj.validate_mode(m)
コード例 #5
0
    def __init__(self, parent=None):
        super().__init__(parent)
        assert cmdutils.cmd_dict
        cmdlist = []
        for obj in set(cmdutils.cmd_dict.values()):
            if (obj.hide or (obj.debug and not objreg.get('args').debug) or
                    obj.deprecated):
                pass
            else:
                cmdlist.append((obj.name, obj.desc))
        for name, cmd in config.section('aliases').items():
            cmdlist.append((name, "Alias for '{}'".format(cmd)))
        cat = self.new_category("Commands")

        # map each command to its bound keys and show these in the misc column
        keyconf = objreg.get('key-config')
        cmd_to_keys = defaultdict(list)
        for key, cmd in keyconf.get_bindings_for('normal').items():
            # put special bindings last
            if utils.is_special_key(key):
                cmd_to_keys[cmd].append(key)
            else:
                cmd_to_keys[cmd].insert(0, key)
        for (name, desc) in sorted(cmdlist):
            self.new_item(cat, name, desc, ', '.join(cmd_to_keys[name]))
コード例 #6
0
    def _validate_command(self, line, modes=None):
        """Check if a given command is valid.

        Args:
            line: The commandline to validate.
            modes: A list of modes to validate the commands for, or None.
        """
        from qutebrowser.config import config
        if line == self.UNBOUND_COMMAND:
            return
        commands = line.split(';;')
        try:
            first_cmd = commands[0].split(maxsplit=1)[0].strip()
            cmd = cmdutils.cmd_dict[first_cmd]
            if cmd.no_cmd_split:
                commands = [line]
        except (KeyError, IndexError):
            pass

        for cmd in commands:
            if not cmd.strip():
                raise KeyConfigError("Got empty command (line: {!r})!".format(
                    line))
        commands = [c.split(maxsplit=1)[0].strip() for c in commands]
        for cmd in commands:
            aliases = config.section('aliases')
            if cmd in cmdutils.cmd_dict:
                cmdname = cmd
            elif cmd in aliases:
                cmdname = aliases[cmd].split(maxsplit=1)[0].strip()
            else:
                raise KeyConfigError("Invalid command '{}'!".format(cmd))
            cmd_obj = cmdutils.cmd_dict[cmdname]
            for m in modes or []:
                cmd_obj.validate_mode(m)
コード例 #7
0
ファイル: miscmodels.py プロジェクト: Dietr1ch/qutebrowser
def _get_cmd_completions(include_hidden, include_aliases, prefix=''):
    """Get a list of completions info for commands, sorted by name.

    Args:
        include_hidden: True to include commands annotated with hide=True.
        include_aliases: True to include command aliases.
        prefix: String to append to the command name.

    Return: A list of tuples of form (name, description, bindings).
    """
    assert cmdutils.cmd_dict
    cmdlist = []
    cmd_to_keys = objreg.get('key-config').get_reverse_bindings_for('normal')
    for obj in set(cmdutils.cmd_dict.values()):
        hide_debug = obj.debug and not objreg.get('args').debug
        hide_hidden = obj.hide and not include_hidden
        if not (hide_debug or hide_hidden or obj.deprecated):
            bindings = ', '.join(cmd_to_keys.get(obj.name, []))
            cmdlist.append((prefix + obj.name, obj.desc, bindings))

    if include_aliases:
        for name, cmd in config.section('aliases').items():
            bindings = ', '.join(cmd_to_keys.get(name, []))
            cmdlist.append((name, "Alias for '{}'".format(cmd), bindings))

    return cmdlist
コード例 #8
0
ファイル: completion.py プロジェクト: larryhynes/qutebrowser
 def __init__(self, parent=None):
     super().__init__(parent)
     assert cmdutils.cmd_dict
     cmdlist = []
     for obj in set(cmdutils.cmd_dict.values()):
         if obj.hide or (obj.debug and not objreg.get('args').debug):
             pass
         else:
             cmdlist.append((obj.name, obj.desc))
     for name, cmd in config.section('aliases').items():
         cmdlist.append((name, "Alias for '{}'".format(cmd)))
     cat = self.new_category("Commands")
     for (name, desc) in sorted(cmdlist):
         self.new_item(cat, name, desc)
コード例 #9
0
 def __init__(self, parent=None):
     super().__init__(parent)
     assert cmdutils.cmd_dict
     cmdlist = []
     for obj in set(cmdutils.cmd_dict.values()):
         if obj.hide or (obj.debug and not objreg.get('args').debug):
             pass
         else:
             cmdlist.append((obj.name, obj.desc))
     for name, cmd in config.section('aliases').items():
         cmdlist.append((name, "Alias for '{}'".format(cmd)))
     cat = self.new_category("Commands")
     for (name, desc) in sorted(cmdlist):
         self.new_item(cat, name, desc)
コード例 #10
0
ファイル: keyconf.py プロジェクト: Dietr1ch/qutebrowser
    def _validate_command(self, line):
        """Check if a given command is valid."""
        from qutebrowser.config import config
        if line == self.UNBOUND_COMMAND:
            return
        commands = line.split(';;')
        try:
            first_cmd = commands[0].split(maxsplit=1)[0].strip()
            cmd = cmdutils.cmd_dict[first_cmd]
            if cmd.no_cmd_split:
                commands = [line]
        except (KeyError, IndexError):
            pass

        for cmd in commands:
            if not cmd.strip():
                raise KeyConfigError("Got empty command (line: {!r})!".format(
                    line))
        commands = [c.split(maxsplit=1)[0].strip() for c in commands]
        for cmd in commands:
            aliases = config.section('aliases')
            if cmd not in cmdutils.cmd_dict and cmd not in aliases:
                raise KeyConfigError("Invalid command '{}'!".format(cmd))
コード例 #11
0
ファイル: keyconf.py プロジェクト: shioyama/qutebrowser
    def _validate_command(self, line):
        """Check if a given command is valid."""
        from qutebrowser.config import config
        if line == self.UNBOUND_COMMAND:
            return
        commands = line.split(';;')
        try:
            first_cmd = commands[0].split(maxsplit=1)[0].strip()
            cmd = cmdutils.cmd_dict[first_cmd]
            if cmd.no_cmd_split:
                commands = [line]
        except (KeyError, IndexError):
            pass

        for cmd in commands:
            if not cmd.strip():
                raise KeyConfigError(
                    "Got empty command (line: {!r})!".format(line))
        commands = [c.split(maxsplit=1)[0].strip() for c in commands]
        for cmd in commands:
            aliases = config.section('aliases')
            if cmd not in cmdutils.cmd_dict and cmd not in aliases:
                raise KeyConfigError("Invalid command '{}'!".format(cmd))