Пример #1
0
 def test_wildcard_matching(self):
     """Test the matching and grouping of shell patterns"""
     for name, pattern, groups in self.matches:
         result = wildcard_to_regex(pattern).match(name)
         if result is not None:
             self.assertEqual(result.groups(), groups)
         else:
             self.assertEqual(None, groups)
Пример #2
0
 def test_wildcard_matching(self):
     """Test the matching and grouping of shell patterns"""
     for name, pattern, groups in self.matches:
         result = wildcard_to_regex(pattern).match(name)
         if result != None:
             self.assertEqual(result.groups(), groups)
         else:
             self.assertEqual(None, groups)
Пример #3
0
 # Print one line
 stdout.write('\r')
 for column in range(0, num_columns):
     if line + column * num_lines < len(
             suggestions):
         s = suggestions[line + column * num_lines]
         if has_wildcards(tokens[-1]):
             # Print wildcard matches in a different color
             path_sep = '/' if '/' in expand_env_vars(
                 tokens[-1]) else '\\'
             tokens = parse_line(
                 completed.rstrip(path_sep))
             token = tokens[-1].replace('"', '')
             (_, _,
              prefix) = token.rpartition(path_sep)
             match = wildcard_to_regex(prefix +
                                       '*').match(s)
             current_index = 0
             for i in range(1, match.lastindex + 1):
                 stdout.write(
                     color.Fore.DEFAULT +
                     color.Back.DEFAULT + appearance
                     .colors.completion_match +
                     s[current_index:match.start(i)]
                     + color.Fore.DEFAULT +
                     color.Back.DEFAULT +
                     s[match.start(i):match.end(i)])
                 current_index = match.end(i)
             stdout.write(color.Fore.DEFAULT +
                          color.Back.DEFAULT + ' ' *
                          (column_width - len(s)))
         else:
Пример #4
0
 suggestion_prefix = ''
 if suggestion_id < num_item_could_choose :
     suggestion_prefix = string.lowercase[suggestion_id]+': '
 elif column < num_col_could_choose :
     suggestion_prefix = '   '
 else :
     suggestion_prefix = ''
 
 stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT + suggestion_prefix)
 
 if has_wildcards(tokens[-1]):
     # Print wildcard matches in a different color
     tokens = parse_line(completed.rstrip('\\'))
     token = tokens[-1].replace('"', '')
     (_, _, prefix) = token.rpartition('\\')
     match = wildcard_to_regex(prefix + '*').match(s)
     current_index = 0
     for i in range(1, match.lastindex + 1):
         stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT +
                      appearance.colors.completion_match +
                      s[current_index : match.start(i)] +
                      color.Fore.DEFAULT + color.Back.DEFAULT +
                      s[match.start(i) : match.end(i)])
         current_index = match.end(i)
     stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT + ' ' * (column_width - len(s)))
 else:
     # Print the common part in a different color
     common_prefix_len = len(find_common_prefix(state.before_cursor, suggestions))
     stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT +
                  appearance.colors.completion_match +
                  s[:common_prefix_len] +
Пример #5
0
                                console.get_buffer_size()[1] -
                                offset_from_bottom)
                            if rec.Char != '\t':
                                if not ord(rec.Char) in [0, 8, 13, 27]:
                                    state.handle(ActionCode.ACTION_INSERT,
                                                 rec.Char)
                                continue

                        if has_wildcards(tokens[-1]):
                            # Substring matching wildcards will be printed in a different color
                            path_sep = '/' if '/' in expand_env_vars(
                                tokens[-1]) else '\\'
                            tokens = parse_line(completed.rstrip(path_sep))
                            token = tokens[-1].replace('"', '')
                            (_, _, prefix) = token.rpartition(path_sep)
                            pattern = wildcard_to_regex(prefix + '*')
                        else:
                            # Length of the common prefix will be printed in a different color
                            common_prefix_len = len(
                                find_common_prefix(state.before_cursor,
                                                   suggestions))

                        stdout.write('\n')
                        for line in range(0, num_lines):
                            # Print one line
                            stdout.write('\r')
                            for column in range(0, num_columns):
                                if line + column * num_lines < len(
                                        suggestions):
                                    s = suggestions[line + column * num_lines]
                                    if has_wildcards(tokens[-1]):
Пример #6
0
                                    suggestion_prefix = ""
                                    if suggestion_id < num_item_could_choose:
                                        suggestion_prefix = string.lowercase[suggestion_id] + ": "
                                    elif column < num_col_could_choose:
                                        suggestion_prefix = "   "
                                    else:
                                        suggestion_prefix = ""

                                    stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT + suggestion_prefix)

                                    if has_wildcards(tokens[-1]):
                                        # Print wildcard matches in a different color
                                        tokens = parse_line(completed.rstrip("\\"))
                                        token = tokens[-1].replace('"', "")
                                        (_, _, prefix) = token.rpartition("\\")
                                        match = wildcard_to_regex(prefix + "*").match(s)
                                        current_index = 0
                                        for i in range(1, match.lastindex + 1):
                                            stdout.write(
                                                color.Fore.DEFAULT
                                                + color.Back.DEFAULT
                                                + appearance.colors.completion_match
                                                + s[current_index : match.start(i)]
                                                + color.Fore.DEFAULT
                                                + color.Back.DEFAULT
                                                + s[match.start(i) : match.end(i)]
                                            )
                                            current_index = match.end(i)
                                        stdout.write(
                                            color.Fore.DEFAULT + color.Back.DEFAULT + " " * (column_width - len(s))
                                        )
Пример #7
0
                            rec = read_input()
                            move_cursor(c_x, console.get_buffer_size()[1] - offset_from_bottom)
                            stdout.write('\n' + ' ' * len(message))
                            move_cursor(c_x, console.get_buffer_size()[1] - offset_from_bottom)
                            if rec.Char != '\t':
                                if not ord(rec.Char) in [0, 8, 13, 27]:
                                    state.handle(ActionCode.ACTION_INSERT, rec.Char)
                                continue

                        if has_wildcards(tokens[-1]):
                            # Substring matching wildcards will be printed in a different color
                            path_sep = '/' if '/' in expand_env_vars(tokens[-1]) else '\\'
                            tokens = parse_line(completed.rstrip(path_sep))
                            token = tokens[-1].replace('"', '')
                            (_, _, prefix) = token.rpartition(path_sep)
                            pattern = wildcard_to_regex(prefix + '*')
                        else:
                            # Length of the common prefix will be printed in a different color
                            common_prefix_len = len(find_common_prefix(state.before_cursor, suggestions))
                            
                        stdout.write('\n')
                        for line in range(0, num_lines):
                            # Print one line
                            stdout.write('\r')
                            for column in range(0, num_columns):
                                if line + column * num_lines < len(suggestions):
                                    s = suggestions[line + column * num_lines]
                                    if has_wildcards(tokens[-1]):
                                        # Print wildcard matches in a different color
                                        match = pattern.match(s)
                                        current_index = 0