def test_find_common_prefix(self): """Test the computation of a common prefix""" for original, completions, result in self.results: self.assertEqual(find_common_prefix(original, completions), result)
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] + color.Fore.DEFAULT + color.Back.DEFAULT + s[common_prefix_len : ]) stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT + ' ' * (column_width - len(s))) stdout.write('\n') # The below code looks a little tricky since it needs to preserve the position of existing result (no flickering) stdout.write('\n') (c_x, c_y) = get_cursor() offset_from_bottom = console.get_buffer_size()[1] - c_y message = ' Press a-z for completion, space to ignore: ' stdout.write(message)
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] + color.Fore.DEFAULT + color.Back.DEFAULT + s[common_prefix_len:]) stdout.write(color.Fore.DEFAULT + color.Back.DEFAULT + ' ' * (column_width - len(s))) stdout.write('\n') state.reset_prev_line() elif rec.Char == chr(8): # Backspace