-
Notifications
You must be signed in to change notification settings - Fork 6
fix: Running CLI editors does not work when piped to rainbow, unlike when piped to the Ruby lolcat #7
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
base: master
Are you sure you want to change the base?
fix: Running CLI editors does not work when piped to rainbow, unlike when piped to the Ruby lolcat #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ import ( | |
|
|
||
| var ( | ||
| // We remove all previous paintings to create a new rainbow. | ||
| colorMatch = regexp.MustCompile("^\033" + `\[\d+(;\d+)?(;\d+)?[mK]`) | ||
| colorMatch = regexp.MustCompile(`\033\[[0-9;]*[mK]`) | ||
|
|
||
| // ErrNilWriter is returned when Light.Writer is nil. | ||
| ErrNilWriter = errors.New("nil writer") | ||
|
|
@@ -87,7 +87,24 @@ func (l *Light) Write(data []byte) (int, error) { | |
| ) | ||
|
|
||
| data = colorMatch.ReplaceAll(data, []byte("")) | ||
| for _, c := range string(data) { | ||
| for i, c := range string(data) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you feel about using an explicitly controlled byte index here instead of |
||
| if c == '\033' { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you feel about accounting for escape sequences split across calls to |
||
| seq := data[i:] | ||
| j := 1 | ||
| if j < len(seq) && seq[j] == '[' { | ||
| for j++; j < len(seq); j++ { | ||
| if (seq[j] >= 'A' && seq[j] <= 'Z') || (seq[j] >= 'a' && seq[j] <= 'z') { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you reckon we could check the complete CSI final-byte range ( |
||
| j++ | ||
| break | ||
| } | ||
| } | ||
| } else if j < len(seq) && (seq[j] == ']' || seq[j] == 'P' || seq[j] == 'X' || seq[j] == '^') { | ||
| for j++; j < len(seq) && seq[j] != 0x1b && seq[j] != 0x07; j++ { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend consuming the complete terminator here. At the moment |
||
| } | ||
| } | ||
| buf.Write(seq[:j]) | ||
| continue | ||
| } | ||
| switch c { | ||
| case '\n': | ||
| offset = 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document and test the intended behaviour here please? This changes the previous anchored match into a global removal, so all matching SGR and erase-line sequences are removed before the new parser has a chance to preserve them. I am not sure whether we want to remove every existing
m/Ksequence or only colours previously produced byrainbow. A test covering an embedded\x1b[Kwould help make that contract clear.