Ejemplo n.º 1
0
def next_complete(str, next_blank_pos, cmd, last_token):
    next_blank_pos, token = Mcomplete.next_token(str, next_blank_pos)

    if hasattr(cmd, "complete_token_with_next"):
        match_pairs = cmd.complete_token_with_next(token)
        if len(match_pairs) == 0:
            return [None]
        if (
            next_blank_pos == len(str)
            and 1 == len(match_pairs)
            and match_pairs[0][0] == token
        ):
            # Add space to advance completion on next tab-complete
            match_pairs[0][0] += " "
            pass
        if next_blank_pos >= len(str):
            return sorted([pair[0] for pair in match_pairs])
        else:
            if len(match_pairs) == 1:
                return next_complete(str, next_blank_pos, match_pairs[0][1], token)
            else:
                return sorted([pair[0] for pair in match_pairs])
                pass
            pass
        pass
    elif hasattr(cmd, "complete"):
        matches = cmd.complete(token)
        if 0 == len(matches):
            return [None]
        return matches
    return [None]
Ejemplo n.º 2
0
def next_complete(str, next_blank_pos, cmd, last_token):
    next_blank_pos, token = Mcomplete.next_token(str, next_blank_pos)

    if hasattr(cmd, 'complete_token_with_next'):
        match_pairs = cmd.complete_token_with_next(token)
        if len(match_pairs) == 0:
            return [None]
        if (next_blank_pos == len(str) and 1 == len(match_pairs) and
            match_pairs[0][0] == token):
            # Add space to advance completion on next tab-complete
            match_pairs[0][0] += " "
            pass
        if next_blank_pos >= len(str):
            return sorted([pair[0] for pair in match_pairs])
        else:
            if len(match_pairs) == 1:
                return next_complete(str, next_blank_pos,  match_pairs[0][1],
                                     token)
            else:
                return sorted([pair[0] for pair in match_pairs])
                pass
            pass
        pass
    elif hasattr(cmd, 'complete'):
        matches = cmd.complete(token)
        if 0 == len(matches):
            return [None]
        return matches
    return [None]
 def test_next_token(self):
     x = '  now is  the  time'
     for pos, expect in [
             [0, [ 5, 'now']],
             [2, [ 5, 'now']],
             [5, [ 8, 'is']],
             [8, [13, 'the']],
             [9, [13, 'the']],
             [13, [19, 'time']],
             [19, [19, '']], ]:
         self.assertEqual(expect, Mcomplete.next_token(x, pos),
                          "Trouble with next_token(%s, %d)" % (x, pos))
         pass
     return
Ejemplo n.º 4
0
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]
Ejemplo n.º 5
0
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]
Ejemplo n.º 6
0
 def test_next_token(self):
     x = '  now is  the  time'
     for pos, expect in [
         [0, [5, 'now']],
         [2, [5, 'now']],
         [5, [8, 'is']],
         [8, [13, 'the']],
         [9, [13, 'the']],
         [13, [19, 'time']],
         [19, [19, '']],
     ]:
         self.assertEqual(expect, Mcomplete.next_token(x, pos),
                          "Trouble with next_token(%s, %d)" % (x, pos))
         pass
     return