[TxMt] Re: how to do HTML <pre>-wrapped output in TextMate 2?

Allan Odgaard mailinglist at textmate.org
Fri Jan 10 03:09:50 UTC 2014


On 7 Jan 2014, at 8:28, Matt Neuburg wrote:

> My bundle command, written in Ruby, looks like this:
>
> s = #... command-line command that produces many lines of output
> STDOUT.sync = true
> puts '<pre>'
> puts `#{s}`
> puts '</pre>'
>
> It is set to output as HTML. In TextMate 1, the result was correctly 
> formatted: line after line of text, wrapped in <pre> tags, wrapped in 
> HTML. In TextMate 2, the opening and closing <pre> tags both appear 
> before the output from executing s, and thus the output is not 
> correctly formatted.
>
> Clearly something has changed. What's the new correct way of doing 
> this? Thanks - m.

This could happen if your command (“s”) outputs to stderr (instead 
of stdout).

You can either redirect the output to stdout or possibly handle both 
stdout and stderr from the command via something like popen3 or 
TextMate::Executor. With the latter, I think you can simply do:

     
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
     require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/executor"

     s = #... command-line command that produces many lines of output
     TextMate::Executor.run(s)

Then the output should be wrapped in the HTML output theme, stderr will 
appear red, etc.


More information about the textmate mailing list