Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
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))
Esempio n. 4
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))
Esempio n. 5
0
    def _paste(self, text):

#        term.savePosition()
        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.restorePosition()
        term.moveBack(len(tail))
Esempio n. 6
0
    def _paste(self, text):

        #        term.savePosition()
        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.restorePosition()
        term.moveBack(len(tail))
Esempio n. 7
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')
Esempio n. 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')
Esempio n. 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()
Esempio n. 10
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()
Esempio n. 11
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
Esempio n. 12
0
 def _showLine(self):
     strLine = self._getLineStr()
     term.write(strLine)
     self._moveDelta(self._position - len(strLine))
Esempio n. 13
0
 def _showPrompt(self):
     term.write(self._context.get_path() + ">>> ")
Esempio n. 14
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
Esempio n. 15
0
 def _showLine(self):
     strLine = self._getLineStr()
     term.write(strLine)
     self._moveDelta(self._position - len(strLine))
Esempio n. 16
0
 def _showPrompt(self):
     term.write(self._context.get_path() + ">>> ")