def complete(self, text, state): """Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions. """ if state == 0: original_line = readline.get_line_buffer() line = original_line.lstrip() stripped = len(original_line) - len(line) start_index = readline.get_begidx() - stripped end_index = readline.get_endidx() - stripped if start_index > 0: cmd, args = self.parse_line(line) if cmd == '': complete_function = self.default_completer else: try: complete_function = getattr(self, 'complete_' + cmd) except AttributeError: complete_function = self.default_completer else: complete_function = self.raw_command_completer self.completion_matches = complete_function( text, line, start_index, end_index) try: return self.completion_matches[state] except IndexError: return None
def complete(self, text, state): """Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions. """ if state == 0: original_line = readline.get_line_buffer() line = original_line.lstrip() stripped = len(original_line) - len(line) start_index = readline.get_begidx() - stripped end_index = readline.get_endidx() - stripped if start_index > 0: cmd, args = self.parse_line(line) if cmd == '': complete_function = self.default_completer else: try: complete_function = getattr(self, 'complete_' + cmd) except AttributeError: complete_function = self.default_completer else: complete_function = self.raw_command_completer self.completion_matches = complete_function(text, line, start_index, end_index) try: return self.completion_matches[state] except IndexError: return None
def complete(self, text, state): """Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions. """ if state == 0: origline = readline.get_line_buffer() # Offer completion just for commands that starts # with the trigger : if origline and not origline.startswith(':'): return None line = origline.lstrip().lstrip(':') stripped = len(origline) - len(line) begidx = readline.get_begidx() - stripped endidx = readline.get_endidx() - stripped if begidx > 0: cmd, args, foo = self.parseline(line) if cmd == '': compfunc = self.completedefault else: try: compfunc = getattr(self, 'complete_' + cmd) except AttributeError: compfunc = self.completedefault else: compfunc = self.completenames self.completion_matches = compfunc(text, line, begidx, endidx) try: return self.completion_matches[state] except IndexError: return None
def complete(self, text, state): response = None if state == 0: # This is the first time for this text, # so build a match list. origline = readline.get_line_buffer() begin = readline.get_begidx() end = readline.get_endidx() being_completed = origline[begin:end] words = origline.split() logging.debug('origline=%s', repr(origline)) logging.debug('begin=%s', begin) logging.debug('end=%s', end) logging.debug('being_completed=%s', being_completed) logging.debug('words=%s', words) if not words: self.current_candidates = sorted( self.options.keys() ) else: try: if begin == 0: # first word candidates = self.options.keys() else: # later word first = words[0] candidates = self.options[first] if being_completed: # match options with portion of input # being completed self.current_candidates = [ w for w in candidates if w.startswith(being_completed) ] else: # matching empty string, # use all candidates self.current_candidates = candidates logging.debug('candidates=%s', self.current_candidates) except (KeyError, IndexError) as err: logging.error('completion error: %s', err) self.current_candidates = [] try: response = self.current_candidates[state] except IndexError: response = None logging.debug('complete(%s, %s) => %s', repr(text), state, response) return response
def complete(self, text, state): response = None if state == 0: # Questa è la prima volta per questo testo, quindi si costruisce # un elenco di corrispondenze origline = readline.get_line_buffer() begin = readline.get_begidx() end = readline.get_endidx() being_completed = origline[begin:end] words = origline.split() logging.debug('riga originale=%s', repr(origline)) logging.debug('inizio=%s', begin) logging.debug('fine=%s', end) logging.debug('in completamento=%s', being_completed) logging.debug('parole=%s', words) if not words: self.current_candidates = sorted(self.options.keys()) else: try: if begin == 0: # prima parola candidates = self.options.keys() else: # parola ulteriore first = words[0] candidates = self.options[first] if being_completed: # cerca corrispondenza di opzioni con la # porzione di input che si sta completando self.current_candidates = [ w for w in candidates if w.startswith(being_completed) ] else: # corrispondenza con una stringa vuota, # quindi si usano tutti i candidati self.current_candidates = candidates logging.debug('candidati=%s', self.current_candidates) except (KeyError, IndexError) as err: logging.error('errore di completamento: %s', err) self.current_candidates = [] try: response = self.current_candidates[state] except IndexError: response = None logging.debug('completato(%s, %s) => %s', repr(text), state, response) return response
def complete(self, text, state): response = None if state == 0: # This is the first time for this text, # so build a match list. origline = readline.get_line_buffer() begin = readline.get_begidx() end = readline.get_endidx() being_completed = origline[begin:end] words = origline.split() logging.debug('origline=%s', repr(origline)) logging.debug('begin=%s', begin) logging.debug('end=%s', end) logging.debug('being_completed=%s', being_completed) logging.debug('words=%s', words) if not words: self.current_candidates = sorted(self.options.keys()) else: try: if begin == 0: # first word candidates = self.options.keys() else: # later word first = words[0] candidates = self.options[first] if being_completed: # match options with portion of input # being completed self.current_candidates = [ w for w in candidates if w.startswith(being_completed) ] else: # matching empty string, # use all candidates self.current_candidates = candidates logging.debug('candidates=%s', self.current_candidates) except (KeyError, IndexError) as err: logging.error('completion error: %s', err) self.current_candidates = [] try: response = self.current_candidates[state] except IndexError: response = None logging.debug('complete(%s, %s) => %s', repr(text), state, response) return response