Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only last instance of repeated pattern gets coloured #115

Open
TheophileMot opened this issue Aug 8, 2023 · 6 comments
Open

Only last instance of repeated pattern gets coloured #115

TheophileMot opened this issue Aug 8, 2023 · 6 comments
Assignees
Labels

Comments

@TheophileMot
Copy link

I tried this example from the docs:

Color in yellow file permissions with read rights for everyone: ls -l | colout '.(r.-){3}' yellow normal

and noticed that in a permission string like -rw-r--r--, only the last three characters were yellow, when I think we would expect the last nine characters (i.e., everything following the initial -) to be yellow.

For a simpler example:

echo test | colout '(.){4}' red

Here the final t is red, even though the match is really all four characters of test.

@nojhan nojhan self-assigned this Aug 23, 2023
@nojhan nojhan added the bug label Aug 23, 2023
@tomasohara
Copy link

This could be by design. If you use outer parentheses, it works better:

$ echo test | colout '(.){4}' red | hexdump --canonical
00000000  74 65 73 1b 5b 31 3b 33  31 6d 74 1b 5b 30 6d 0a  |tes.[1;31mt.[0m.|
00000010

$ echo test | colout '((.){4})' red | hexdump --canonical
00000000  1b 5b 31 3b 33 31 6d 74  65 73 74 1b 5b 30 6d 1b  |.[1;31mtest.[0m.|
00000010  5b 31 3b 33 31 6d 74 1b  5b 30 6d 0a              |[1;31mt.[0m.|
0000001c

This reveals a separate issue, namely extraneous text added (i.e., "[test]t"). I'm in the course of documenting that.

@TheophileMot
Copy link
Author

@tomasohara Thanks for looking into this. I had already tried your idea of using outer parentheses, but unfortunately the extraneous text made it unusable for what I needed to do. I don't think there's an issue for this, but it is mentioned on the main page under Limitations ("Don't use nested groups").

@nojhan
Copy link
Owner

nojhan commented Oct 15, 2023

This seem tricky to fix, given that groups have two meanings for colout (one for regexp, one for coloring).

@TheophileMot
Copy link
Author

TheophileMot commented Oct 15, 2023

@nojhan How about parsing the input string to find the outer groups? For example, given ((abc)(def)gh)(ijkl), you could store outer_groups = [1, 4], and then iterate over that list instead of all groups.

@nojhan
Copy link
Owner

nojhan commented Oct 16, 2023

I unfortunately don't have time for this in a near future, but I am open to merging a pull request that would do that.

@TheophileMot
Copy link
Author

@nojhan I thought about it and came up with an idea that's even simpler than parsing the input string: just let the user do it on the command line through another argument. This has the additional advantage of generally addressing your above point that "groups have two meanings for colout (one for regexp, one for coloring)", because now the user can decide which is which.

I made a pull request (#117) but I don't know Python so it will surely need tweaking; I used a global variable when I got stuck, but otherwise it seems to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants