I don't necessarily need code examples -- but if anyone has ideas for a
best approach to specifying a line wrap width (breaking between words
for lines no longer than a specific column width) for output from a Ruby
script, I'd love to hear about it.
···
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Paul Graham: "Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts."
On 4/27/07, Chad Perrin <perrin@apotheon.com> wrote:
I don't necessarily need code examples -- but if anyone has ideas for a
best approach to specifying a line wrap width (breaking between words
for lines no longer than a specific column width) for output from a Ruby
script, I'd love to hear about it.
str = "\
I don't necessarily need code examples -- but if anyone has
ideas for a best approach to specifying a line wrap width
(breaking between words for lines no longer than a specific
column width) for output from a Ruby script, I'd love to
hear about it."
X = 40
puts str.gsub(/\n/," ").scan(/\S.{0,#{X-2}}\S(?=\s|$)|\S+/)
--- output ---
I don't necessarily need code examples
-- but if anyone has ideas for a best
approach to specifying a line wrap width
(breaking between words for lines no
longer than a specific column width) for
output from a Ruby script, I'd love to
hear about it.
···
On Apr 27, 4:25 am, Chad Perrin <per...@apotheon.com> wrote:
I don't necessarily need code examples -- but if anyone has ideas for a
best approach to specifying a line wrap width (breaking between words
for lines no longer than a specific column width) for output from a Ruby
script, I'd love to hear about it.
--
CCD CopyWrite Chad Perrin [http://ccd.apotheon.org]
Paul Graham: "Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts."
irb(main):001:0> require 'prettyprint'
=> false
irb(main):003:0> s = "The quick brown fox jumped over the lazy dog. Now is the time for all good men to come to the aid of their country. You have been warned."
irb(main):015:0> puts PrettyPrint.format('', 80) { |q|
irb(main):016:1* s.scan(/\S+/) { |t|
irb(main):017:2* q.group { q.text t; q.breakable }
irb(main):018:2> }
irb(main):019:1> }
The quick brown fox jumped over the lazy dog. Now is the time for all good men
to come to the aid of their country. You have been warned.
=> nil
I get the feeling I'm not doing this quite right, since this strips out
newlines and doesn't retain multiple spaces from the original string.
Perhaps there's a prettyprint expert out there who knows how to do this
better.
Paul
···
On Fri, Apr 27, 2007 at 06:25:24PM +0900, Chad Perrin wrote:
I don't necessarily need code examples -- but if anyone has ideas for a
best approach to specifying a line wrap width (breaking between words
for lines no longer than a specific column width) for output from a Ruby
script, I'd love to hear about it.
On Apr 27, 3:25 am, Chad Perrin <per...@apotheon.com> wrote:
I don't necessarily need code examples -- but if anyone has ideas for a
best approach to specifying a line wrap width (breaking between words
for lines no longer than a specific column width) for output from a Ruby
script, I'd love to hear about it.
On Fri, Apr 27, 2007 at 06:38:45PM +0900, Martin DeMello wrote:
On 4/27/07, Chad Perrin <perrin@apotheon.com> wrote:
>I don't necessarily need code examples -- but if anyone has ideas for a
>best approach to specifying a line wrap width (breaking between words
>for lines no longer than a specific column width) for output from a Ruby
>script, I'd love to hear about it.
Check out Text::Format
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
print substr("Just another Perl hacker", 0, -2);