From 645c9e062ad6d1c8e7a1902624290335c4e6ce27 Mon Sep 17 00:00:00 2001 From: Timothy Mott Date: Wed, 18 Oct 2023 17:58:12 -0400 Subject: [PATCH] Fix colour cycling --- colout/colout.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index 6b0fdbe..d30f374 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -699,7 +699,10 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False, sep_lis colored_text += partial else: - nb_groups = len(match.groups()) + if (target_groups == None): + nb_groups = len(match.groups()) + else: + nb_groups = len(target_groups) # Build a list of colors that match the number of grouped, # if there is not enough colors, duplicate the last one. @@ -723,10 +726,10 @@ def colorup(text, pattern, color="red", style="normal", on_groups=False, sep_lis if (target_groups == None): target_groups = range(1, nb_groups+1) - for group in target_groups: + for index, group in enumerate(target_groups): # If a group didn't match, there's nothing to color if match.group(group) is not None: - partial, end = colorout(text, match, end, group_colors[group-1], group_styles[group-1], group) + partial, end = colorout(text, match, end, group_colors[index], group_styles[index], group) colored_text += partial # Append the remaining part of the text, if any.