Closed nielsbuus closed 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.
@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!
Thanks - out of curiosity - what was the motivation for rewriting in Go?
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.
It looks like this tool used to be a Ruby library.
Where did the Ruby code go? And does it still work?