buildkite / terminal-to-html

Converts arbitrary shell output (with ANSI) into beautifully rendered HTML
http://buildkite.github.io/terminal-to-html
MIT License
658 stars 44 forks source link

Handles <ESC>[J and <ESC>M #68

Closed wasv closed 4 years ago

wasv commented 4 years ago

Clears lines below current line on [J, clears entire scrollback buffer on [2J or [3J. Also includes support for M, reverse linefeed, which is used alongside [J in zsh.

Fixes #2

ticky commented 4 years ago

Hi @wasv, thanks for this! Are you able to provide us with some examples of using this behaviour so we can implement some tests?

wasv commented 4 years ago

I saw this issue most often was when using autocomplete in zsh. I've attached an example, captured using the script command, and the html file generated from that example by the patched version of the code.

zsh-autocomplete.html.txt

zsh-autocomplete.txt

wasv commented 4 years ago

A lot has happened in the world since I made this PR and #67. I can understand why they may have fallen into the backlog. However, I was wondering if they could be merged at some point? That way I can use the upstream instead of building my fork each time.

If any additional work is needed, please let me know.

ticky commented 4 years ago

Hey @wasv, I’m sorry that this one’s not been a high priority and has fallen a bit by the wayside.

Given the potentially high-impact nature of changes to this for us, we’d really prefer them to have test coverage, and while I initially had intended to add that myself, it’s been a very weird year and other things have pulled our collective attention elsewhere.

If you’d be able to add some specs for each of the escape codes you’ve added I’m sure we could get this merged, though!

ticky commented 4 years ago

I wound up down a very deep rabbit hole of reading specs and testing terminal behaviours with this one today! 😂 I’ve pushed a few commits, and I hope they meet with your approval.

  1. Given \x1b[2J clears the screen, I’ve updated it to reset the size of the screen and the position of the cursor. The cursor is reset in all the terminals I’ve tested, so I believe this is correct.
  2. I’ve implemented \x1b[1J, because everywhere I could find reference for these, that one was mentioned, and I figured it was worth adding!
  3. The \x1b[J handler didn’t remove the following lines, just blanked them out, meaning you could end up with erroneously “long” output; I’ve updated it to remove the lines instead
  4. I’ve added some simple tests which should cover all of the stuff we’ve added

Wherever possible, I’ve followed the lead of xterm, iTerm 2 and Apple Terminal, and all seem to agree with the implementation I’ve ended up with. I’ve also sourced some of the explanations of codes, and borrowed some names, from https://www.real-world-systems.com/docs/ANSIcode.html

I will be passing this to some golang-speaking colleagues for their input and merge approval, but I’d also love your thoughts on this. Apologies again for taking so long to get here, and thanks so much for caring enough to open this! 😃

wasv commented 4 years ago

Thank you for looking into this. Your commits look good to me, however, I actually don't know Go. I learned it for this PR. I'll check if this fixes the issues I was having with zsh autocomplete.

wasv commented 4 years ago

I was able to get this code to build and run, and it does fix the issues I was having with zsh autocomplete. However, I ran into some unrelated issues with the Dockerfile, which I described in a new issue.

ticky commented 4 years ago

Thanks for this, @wasv!