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

Fix/non color escape2 #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

inkarkat
Copy link
Contributor

When smashing various keys for an interactive test of nowrap, I managed to obtain a long Use of uninitialized value $esc_seq error, apparently by typing a standalone escape.

The fix to prevent the error is simple (cp. bef829e), but accounting for the correct width of non-ASCII sequence escapes led me down a rabbit hole. I can't guarantee this is entirely correct (and the behavior might differ in other terminals), but for a corner case (that I only found by accident, not real data), I think it should be better than the original behavior, is documented by an added test, and doesn't add too much additional complexity to the code.

An escape character that is not part of an ANSI escape sequence (i.e. does not match $ESCAPE_SEQUENCE_PATTERN) produces undef as the submatch because the success of the pattern matching isn't checked.
> $ nowrap
> foo^[bar
> Use of uninitialized value $esc_seq in subtraction (-) at nowrap line 147, <> line 1.
> Use of uninitialized value in addition (+) at nowrap line 148, <> line 1.
> Use of uninitialized value $append in concatenation (.) or string at nowrap line 171, <> line 1.
> Use of uninitialized value $esc_seq in subtraction (-) at nowrap line 147, <> line 1.
> Use of uninitialized value in addition (+) at nowrap line 148, <> line 1.
> Use of uninitialized value $append in concatenation (.) or string at nowrap line 171, <> line 1.

Move the pattern matching into the condition, so that the branch only is taken if the pattern actually matches.
The observed behavior (in Gnome terminal) is that runs of adjacent escapes plus a following non-escape character are invisible; i.e. do not contribute to the line length.
By modifying $ESCAPE_SEQUENCE_PATTERN, the correction automatically also applies to a passed --indent-string.
These are also swallowed, until (and including) the next non-escape non-space character.
In contrast to spaces, tabs within the escape sequence are not swallowed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant