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

Matt Neuburg matt at tidbits.com
Fri Jan 10 19:10:31 UTC 2014


On Jan 9, 2014, at 7:09 PM, Allan Odgaard <mailinglist at textmate.org> wrote:

> 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).

Great suggestion, thanks! As you advised, I dealt with this by calling popen3 (actually I used popen2e):

puts "<pre>"
puts "Converting #{f}..."
require 'open3'
Open3.popen2e(s) do |i,o,t|
  puts o.read
end
puts "</pre>"

Unfortunately all the output appears at once; it would be nice to get each line of output to appear as it arrives. But one can't have everything...

TextMate::Executor.run() is worth knowing about, but I couldn't get it to work in this case, as it seems to expect a Ruby file. Thanks again, this worked great. m.

--
matt neuburg, phd = matt at tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 7! http://shop.oreilly.com/product/0636920031017.do
iOS 7 Fundamentals! http://shop.oreilly.com/product/0636920032465.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com



More information about the textmate mailing list