def completer(self, str, state, last_token=''): next_blank_pos, token = Mcomplete.next_token(str, 0) if len(token) == 0 and not 0 == len(last_token): return ['', None] match_pairs = Mcomplete.complete_token_with_next(self.commands, token) match_hash = {} for pair in match_pairs: match_hash[pair[0]] = pair[1] pass alias_pairs = Mcomplete \ .complete_token_filtered_with_next(self.aliases, token, match_hash, list(self.commands.keys())) match_pairs += alias_pairs macro_pairs = Mcomplete \ .complete_token_filtered_with_next(self.macros, token, match_hash, self.commands.keys()) match_pairs += macro_pairs if len(str) == next_blank_pos: if len(match_pairs) == 1 and match_pairs[0][0] == token: # Add space to advance completion on next tab-complete match_pairs[0][0] += " " pass return sorted([pair[0] for pair in match_pairs]) + [None] else: for pair in alias_pairs: match_hash[pair[0]] = pair[1] pass pass if len(match_pairs) > 1: # FIXME: figure out what to do here. # Matched multiple items in the middle of the string # We can't handle this so do nothing. return [None] # return match_pairs.map do |name, cmd| # ["#{name} #{args[1..-1].join(' ')}"] # len(match_pairs) == 1 if str[-1] == ' ' and str.rstrip().endswith(token): token = '' pass return next_complete(str, next_blank_pos, match_pairs[0][1], token) + [None]
def completer(self, str, state, last_token=''): next_blank_pos, token = Mcomplete.next_token(str, 0) if len(token) == 0 and not 0 == len(last_token): return ['', None] match_pairs = Mcomplete.complete_token_with_next(self.commands, token) match_hash = {} for pair in match_pairs: match_hash[pair[0]] = pair[1] pass alias_pairs = Mcomplete \ .complete_token_filtered_with_next(self.aliases, token, match_hash, list(self.commands.keys())) match_pairs += alias_pairs macro_pairs = Mcomplete \ .complete_token_filtered_with_next(self.macros, token, match_hash, self.commands.keys()) match_pairs += macro_pairs if len(str) == next_blank_pos: if len(match_pairs) == 1 and match_pairs[0][0] == token: # Add space to advance completion on next tab-complete match_pairs[0][0] += " " pass return sorted([pair[0] for pair in match_pairs]) + [None] else: for pair in alias_pairs: match_hash[pair[0]] = pair[1] pass pass if len(match_pairs) > 1: # FIXME: figure out what to do here. # Matched multiple items in the middle of the string # We can't handle this so do nothing. return [None] # return match_pairs.map do |name, cmd| # ["#{name} #{args[1..-1].join(' ')}"] # len(match_pairs) == 1 if str[-1] == ' ' and str.rstrip().endswith(token): token='' pass return next_complete(str, next_blank_pos, match_pairs[0][1], token) + [None]
def test_complete(self): hash = {'ab': 1, 'aac': 2, 'aa': 3, 'a': 4} ary = sorted(hash.keys()) for result, prefix in [[[], 'b'], [ary, 'a'], [['aa', 'aac'], 'aa'], [ary, ''], [['ab'], 'ab'], [[], 'abc']]: self.assertEqual(result, Mcomplete.complete_token(ary, prefix), "Trouble matching %s on %s" % (repr(ary), prefix)) pass for result_keys, prefix in [[ary, 'a'], [['aa', 'aac'], 'aa'], [['ab'], 'ab'], [[], 'abc']]: result = [[key, hash[key]] for key in result_keys] self.assertEqual( result, Mcomplete.complete_token_with_next(hash, prefix), "Trouble matching %s on %s" % (repr(hash), prefix)) pass return
def test_complete(self): hash = {'ab': 1, 'aac': 2, 'aa': 3, 'a': 4} ary = sorted(hash.keys()) for result, prefix in [ [[], 'b'], [ary, 'a'], [['aa', 'aac'], 'aa'], [ary, ''], [['ab'], 'ab'], [[], 'abc']]: self.assertEqual(result, Mcomplete.complete_token(ary, prefix), "Trouble matching %s on %s" % (repr(ary), prefix)) pass for result_keys, prefix in [ [ary, 'a'], [['aa', 'aac'], 'aa'], [['ab'], 'ab'], [[], 'abc']]: result = [[key, hash[key]] for key in result_keys] self.assertEqual(result, Mcomplete.complete_token_with_next(hash, prefix), "Trouble matching %s on %s" % (repr(hash), prefix)) pass return
def complete_token_with_next(self, prefix): result = Mcomplete.complete_token_with_next(self.cmds.subcmds, prefix) return result
def complete_token_with_next(self, prefix): # from trepan.api import debug; debug() result = Mcomplete.complete_token_with_next(self.cmds.subcmds, prefix) return result