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)
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))
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))
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')
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()
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()
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
def _showLine(self): strLine = self._getLineStr() term.write(strLine) self._moveDelta(self._position - len(strLine))
def _showPrompt(self): term.write(self._context.get_path() + ">>> ")