class DefaultMatcher(AbstractMatcher): """Default matcher: delegate to standard's `rlcompleter.Completer`` class """ def __init__(self, local_ctx): self.completer = Completer(local_ctx) def possible_matches(self, text): if "." in text: return self.completer.attr_matches(text) else: return self.completer.global_matches(text)
def tabComplete(self): try: from rlcompleter import Completer c = Completer(self.namespace) cmd = self.getCommand() if "." in cmd: matches = c.attr_matches(cmd) else: matches = c.global_matches(cmd) if len(matches) == 1: cmd = matches[0] else: self.appendPlainText("\t".join(matches)) self.newPrompt() self.setCommand(cmd) except ImportError, e: log.error(e)
def tab_complete(self): try: from rlcompleter import Completer c = Completer(self.namespace) cmd = self.getCommand() if "." in cmd: matches = c.attr_matches(cmd) else: matches = c.global_matches(cmd) if len(matches) == 1: cmd = matches[0] else: self.appendPlainText("\t".join(matches)) self.newPrompt() self.setCommand(cmd) except ImportError, e: log(e)
def secondary_matches(self, text, line): """Compute matches for tokens when not at start of line""" # Check first character following initial alphabetic string. # If next char is alphabetic (or null) use filename matches. # Also use filename matches if line starts with '!'. # Otherwise use matches from Python dictionaries. lt = len(line) - len(text) if line[:1] == "!": # Matching filename for OS escapes # Ideally would use tcsh-style matching of commands # as first argument, but that looks unreasonably hard return self.filename_matches(text, line[:lt]) m = self.taskpat.match(line) if m is None or keyword.iskeyword(m.group(1)): if line[lt - 1:lt] in ['"', "'"]: # use filename matches for quoted strings return self.filename_matches(text, line[:lt]) else: if not hasattr(self, "namespace"): self.namespace = {} return Completer.global_matches(self, text) else: taskname = m.group(1) # check for pipe/redirection using last non-blank character mpipe = re.search(r"[|><][ \t]*$", line[:lt]) if mpipe: s = mpipe.group(0) if s[0] == "|": # pipe -- use task matches return iraf.getAllMatches(text) else: # redirection -- just match filenames return self.filename_matches(text, line[:lt]) elif taskname in taskArgDict: # task takes task names as arguments return iraf.getAllTasks(text) elif taskname in pkgArgDict: # task takes package names as arguments return iraf.getAllPkgs(text) else: return self.argument_matches(text, taskname, line)
def secondary_matches(self, text, line): """Compute matches for tokens when not at start of line""" # Check first character following initial alphabetic string. # If next char is alphabetic (or null) use filename matches. # Also use filename matches if line starts with '!'. # Otherwise use matches from Python dictionaries. lt = len(line)-len(text) if line[:1] == "!": # Matching filename for OS escapes # Ideally would use tcsh-style matching of commands # as first argument, but that looks unreasonably hard return self.filename_matches(text, line[:lt]) m = self.taskpat.match(line) if m is None or keyword.iskeyword(m.group(1)): if line[lt-1:lt] in ['"', "'"]: # use filename matches for quoted strings return self.filename_matches(text, line[:lt]) else: return Completer.global_matches(self,text) else: taskname = m.group(1) # check for pipe/redirection using last non-blank character mpipe = re.search(r"[|><][ \t]*$", line[:lt]) if mpipe: s = mpipe.group(0) if s[0] == "|": # pipe -- use task matches return iraf.getAllMatches(text) else: # redirection -- just match filenames return self.filename_matches(text, line[:lt]) elif taskArgDict.has_key(taskname): # task takes task names as arguments return iraf.getAllTasks(text) elif pkgArgDict.has_key(taskname): # task takes package names as arguments return iraf.getAllPkgs(text) else: return self.argument_matches(text, taskname, line)
def handle_TAB1(self): head_line, tail_line = self.currentLineBuffer() search_line = head_line completer = Completer(self.namespace) def find_term(line): chrs = [] attr = False for c in reversed(line): if c == '.': attr = True if not c.isalnum() and c not in ('_', '.'): break chrs.insert(0, c) return ''.join(chrs), attr search_term, attrQ = find_term(search_line) if not search_term: return manhole.Manhole.handle_TAB(self) if attrQ: matches = completer.attr_matches(search_term) matches = list(set(matches)) matches.sort() else: matches = completer.global_matches(search_term) def same(*args): if len(set(args)) == 1: return args[0] return False def progress(rem): letters = [] while True: letter = same(*[elm.pop(0) for elm in rem if elm]) if letter: letters.append(letter) else: return letters if matches is not None: rem = [list(s.partition(search_term)[2]) for s in matches] more_letters = progress(rem) # print 'LEN MATCHES', len(matches), more_letters # if len(matches) == 1: # length = len(search_line) # self.lineBuffer = self.lineBuffer[:-length] # self.lineBuffer.extend([matches[0]]+more_letters) # self.lineBufferIndex = len(self.lineBuffer) if len(matches) > 1: match_str = "%s \t\t" * len(matches) % tuple(matches) match_rows = text.greedyWrap(match_str) # line = self.lineBuffer self.terminal.nextLine() self.terminal.saveCursor() for row in match_rows: self.addOutput(row, True) if tail_line: self.terminal.cursorBackward(len(tail_line)) self.lineBufferIndex -= len(tail_line) # self.addOutput("".join(more_letters), True) self._deliverBuffer(more_letters)