Example #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()
Example #2
0
    def _setLine(self, line):
        term.moveBack(self._position)
        term.write(' ' * len(self._line))
        term.moveBack(len(self._line))
#        term.eraseLine()
        term.write(''.join(line))
        self._line = line
        self._position = len(line)
Example #3
0
    def _paste(self, text):
        tail = self._line[self._position:]
        for c in text:
            self._line.insert(self._position, c)
            self._position += 1

        term.write(text)
        term.write(''.join(tail))
        term.moveBack(len(tail))
Example #4
0
    def _paste(self, text):
        tail = self._line[self._position:]
        for c in text:
            self._line.insert(self._position, c)
            self._position += 1

        term.write(text)
        term.write(''.join(tail))
        term.moveBack(len(tail))
Example #5
0
 def _showTail(self, retainPosition=True):
     """
         reprint everything that should be after the cursor
     """
     strLine = self._getLineStr()
     toWrite = strLine[self._position:]
     term.write(toWrite)
     if retainPosition:
         term.moveBack(len(toWrite))
Example #6
0
    def _showTail(self, retainPosition=True):
        """
            reprint everything that should be after the cursor
        """
#        term.savePosition()
        strLine = self._getLineStr()
        toWrite = strLine[self._position:]
        term.write(toWrite)
        if retainPosition:
            term.moveBack(len(toWrite))
Example #7
0
    def _paste(self, text): # 将用户输入的正常字符添加到_line中,并刷新term显示

#        term.savePosition()
        tail = self._line[self._position:] #初始 _line、_position均为 0
        for c in text: #用户每敲击一个字符,添加到_line中
            self._line.insert(self._position, c)
            self._position += 1

        term.write(text)
        term.write(''.join(tail))
#        term.restorePosition()
        term.moveBack(len(tail))
Example #8
0
    def _parseLine(self, line=None):
        """
        >>> console = ConsoleUI(do_upd=False)
        >>> console._parseLine('abc')
        ['abc']

        >>> console._parseLine('abc def')
        ['abc', 'def']

        >>> console._parseLine('abc "def jkl"')
        ['abc', 'def jkl']

        >>> console._parseLine('abc "def jkl')
        No closing quotation

        """
        if line is None:
            line = self._getLineStr()

        try:
            result = shlex.split(line)
        except ValueError, ve:
            term.write(str(ve) + '\n')
Example #9
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()
Example #10
0
 def _moveForward(self, steps=1):
     for i in range(steps):
         if self._position == len(self._line):
             term.bell()
     term.write(self._line[self._position])
     self._position += 1
Example #11
0
 def _showLine(self):
     strLine = self._getLineStr()
     term.write(strLine)
     self._moveDelta(self._position - len(strLine))
Example #12
0
 def _showPrompt(self):
     term.write(self._context.get_path() + ">>> ")
Example #13
0
 def _showPrompt(self):
     prompt = colored(self._context.get_path() + '>>> ', 'blue')
     term.write(prompt)
Example #14
0
 def _showPrompt(self):
     prompt = colored(self._context.get_path() + ">>> ", "blue")
     term.write(prompt)