def complete(self, text, state): "Generic readline completion entry point." results = [w for w in self.words if w.startswith(text)] + [None] if results != [None]: return results[state] buffer = readline.get_line_buffer() line = readline.get_line_buffer().split() results = [w for w in self.words if w.startswith(text)] + [None] if results != [None]: return results[state] # account for last argument ending in a space if RE_SPACE.match(buffer): line.append("") return (self.complete_extra(line) + [None])[state]
def complete_path(self, text, state): line_beginning = readline.get_line_buffer()[:readline.get_begidx()] if "(" not in line_beginning: return [] """ Expand file paths for several functions. """ candidates = [i for i in KEYKIT_FILE_RELEATED_FUNCTIONS if i[0] in line_beginning] if len(candidates) == 0: return [] for candidate in candidates: re_split_args = "([^=]*=)?\s*%s\s*\(([^,]+,){%d}" % candidate if re.search(re_split_args, line_beginning) is not None: # Note that text is to short du the default delims setting. text2 = readline.get_line_buffer() text2 = text2[text2.rfind('"')+1:] return self.shell.update_lsdir(text2, 3) break return []
def print_callback(self, path, tags, args, source, textColor=ColorOut): current_input = readline.get_line_buffer() # Add Tab at every input line out = args[0].replace("\n", "\n\t") # Delete current input, insert output and add input again. # \r : Carriage return, \033[K : Delete everything after the cursor. sys.stdout.write("\r\033[K") sys.stdout.write( "\t%s%s%s\n%s%s" % (textColor, out, ColorReset, MY_PROMPT, current_input)) sys.stdout.flush()
o.append( formatstring.format(num+1)+'|'+c[num] ) return o text=textin #Complete \t to tabs if text[-2:]=='\\t': if state==0: return text[:-2]+'\t' else: return prefix='' localtables=[] completions=[] linebuffer=readline.get_line_buffer() beforecompl= linebuffer[0:readline.get_begidx()] # Only complete '.xxx' completions when space chars exist before completion if re.match(r'\s*$', beforecompl): completions+=dotcompletions # If at the start of the line, show all tables if beforecompl=='' and text=='': localtables=alltables[:] # Check if all tables start with the same character if localtables!=[]: prefcharset=set( (x[0] for x in localtables) ) if len(prefcharset)==1: localtables+=[' ']
text = textin # Complete \t to tabs if text[-2:] == '\\t': if state == 0: return text[:-2] + '\t' else: return prefix = '' localtables = [] completions = [] linebuffer = readline.get_line_buffer() beforecompl = linebuffer[0:readline.get_begidx()] # Only complete '.xxx' completions when space chars exist before completion if re.match(r'\s*$', beforecompl): completions += dotcompletions # If at the start of the line, show all tables if beforecompl == '' and text == '': localtables = alltables[:] # Check if all tables start with the same character if localtables != []: prefcharset = set((x[0] for x in localtables)) if len(prefcharset) == 1: localtables += [' ']