Пример #1
0
    def _onTab(self):
        """
            Autocompletion logic is called here
        """

        # TODO: autocomplete for raw menu
        if self.in_raw_line_mode():
            return

        line = self._getLineStr()[: self._position]  # take the line before the cursor
        tokens = self._parseLine(line)
        if not line.endswith(" ") and len(tokens) > 0:
            # if the cursor is after non-space, the last word is used
            # as a hint for autocompletion
            incomplete = tokens.pop()
        else:
            incomplete = ""

        completions = self._context.suggest(tokens, incomplete)
        if completions is None:
            return
        prefix = commonPrefix(completions)
        if prefix != "":
            self._paste(prefix)
        elif len(completions) > 0:
            term.writeln()
            for variant in map(lambda c: c[1], completions):
                term.write(variant + " ")
            term.writeln()

            self._showPrompt()

            self._showLine()
        else:
            term.bell()
Пример #2
0
    def _onTab(self):
        """
            Autocompletion logic is called here
        """

        # TODO: autocomplete for raw menu
        if self.in_raw_line_mode():
            return

        line = self._getLineStr(
        )[:self._position]  # take the line before the cursor
        tokens = self._parseLine(line)
        if not line.endswith(' ') and len(tokens) > 0:
            # if the cursor is after non-space, the last word is used
            # as a hint for autocompletion
            incomplete = tokens.pop()
        else:
            incomplete = ''

        completions = self._context.suggest(tokens, incomplete)
        if completions is None:
            return
        prefix = commonPrefix(completions)
        if prefix != '':
            self._paste(prefix)
        elif len(completions) > 0:
            term.writeln()
            for variant in map(lambda c: c[1], completions):
                term.write(variant + ' ')
            term.writeln()

            self._showPrompt()

            self._showLine()
        else:
            term.bell()