buildkite / terminal-to-html

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

Ruby? #62

Closed nielsbuus closed 5 years ago

nielsbuus commented 5 years ago

It looks like this tool used to be a Ruby library.

Where did the Ruby code go? And does it still work?

ticky commented 5 years ago

The last Ruby version was v2.0.0, tagged back in 2015. It’s still available on Rubygems. We’ve just been using and maintaining the Go version since #14 landed.

keithpitt commented 5 years ago

@nielsbuus we still use this library from Ruby, we have some code that looks like this:

TERMINAL_TO_HTML_BINARY = if RUBY_PLATFORM.match? /darwin/
                            'terminal-to-html-darwin-amd64'
                          else
                            'terminal-to-html-linux-amd64'
                          end

def render(output)
  binary = Rails.root.join('bin', TERMINAL_TO_HTML_BINARY).to_s

  html = IO.popen([binary], 'r+') do |p|
    p.write(output)
    p.close_write
    p.read
  end

  raise Error.new('Failed to render terminal output') if $?.to_i != 0

  html
end

Works a treat!

nielsbuus commented 5 years ago

Thanks - out of curiosity - what was the motivation for rewriting in Go?

mipearson commented 5 years ago

Speed and memory.

I hacked together a prototype implementation during a CampJS years ago as a Go teaching exercise and asked if BK wanted to use it.

The initial implementation was 2x as fast as Ruby - what I found was that both Go and Ruby were spending most of their time in regex land: in Ruby, this was much faster than the ruby surrounding it, but that was not true for Go. Rewrote the parsing engine to be state/token based and got to a (can't remember exactly) 10x or so speedup.