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

Escape Sequences get partially stripped #182

Closed
h4emp3 opened this issue Jul 3, 2018 · 8 comments
Closed

Escape Sequences get partially stripped #182

h4emp3 opened this issue Jul 3, 2018 · 8 comments
Labels
bug Something isn't working
Milestone

Comments

@h4emp3
Copy link

h4emp3 commented Jul 3, 2018

Command to reproduce: echo -e '\033[1;3mfoo\033[22m bar\033[23m baz' | bat.
Expected output: foo bar baz
Actual output: foo bar baz

Note that bar should be still italic, but it is not when piped through bat. I cannot reproduce this behaviour with other pagers (less, most) or any other shell utility for that matter.

@sharkdp sharkdp added the bug Something isn't working label Jul 4, 2018
@sharkdp
Copy link
Owner

sharkdp commented Jul 4, 2018

Thank you very much for reporting this.

@sharkdp
Copy link
Owner

sharkdp commented Jul 5, 2018

@eth-p Just in case you have time to look at this: could this be caused by the console::AnsiCodeIterator?

@eth-p
Copy link
Collaborator

eth-p commented Jul 5, 2018

This is a difficult case to handle. The current implementation will only copy the previously-encountered escape sequence, which ends up stripping any others that came before it. And unfortunately, the escape sequence can't just be sent through directly, because the panel/syntax highlighting will end up overriding some of the escape sequences anyways (e.g. color).

The only alternatives I can think of are:

  1. Blindly add every encountered escape sequence to a buffer and copy it all over on every line. This would work perfectly with SGR (color/style) sequences, but cause major issues with other sequences that move the cursor or alter some terminal setting that depends on the cursor position.

  2. Attempt to track the SGR codes, and reproduce them on every line. To make this work properly without mangling the order of sequences or breaking something, it would add a significant amount of complexity (and still probably end up with missing functionality).

For now, I'm going to attempt a hybrid of option 1 and 2 by storing and blindly just copying every encountered SGR sequence before the print, and passing through all non-SGR sequences.

@sharkdp
Copy link
Owner

sharkdp commented Jul 5, 2018

@h4emp3 Just for the record, this is related to character-level wrapping. The bug does not appear when using bat --wrap=never.

@eth-p Thank you for the analysis!

eth-p added a commit to eth-p/bat that referenced this issue Jul 5, 2018
@eth-p
Copy link
Collaborator

eth-p commented Jul 5, 2018

@sharkdp I made a pull request for a partial (hacky?) fix as described above. Just waiting on the CI build checks to finish.

@h4emp3
Copy link
Author

h4emp3 commented Jul 9, 2018

Kudos for the quick action you guys took!

Is it not possible to actually track the state for at least the text styling sequences (italic, bold etc)?
I'm not quite certain what is involved in this particular case, but if enough abstractions for different terminals etc are already in place, it should not be too much of a nightmare to do that I guess...

@sharkdp
Copy link
Owner

sharkdp commented Jul 11, 2018

@h4emp3 This is pretty much what @eth-p does in #185.

@sharkdp sharkdp added this to the v0.5.0 milestone Aug 19, 2018
@sharkdp
Copy link
Owner

sharkdp commented Aug 19, 2018

Fix released in bat 0.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants