[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Formatting (ANSI) highlighted strings

Austin Ziegler

10/28/2003 3:54:00 PM

On Tue, 28 Oct 2003 17:32:13 +0900, Gavin Sinclair wrote:
> Using the 'text/highlight' package on RubyForge, you can emit coloured
> strings to the console like so:
> s = "string".bold.red.on_white
> Great. Now if I want to format that using:
> printf "%-10s goes here\n", s
> I'm not going to get (in B&W)
> string goes here
> Rather
> string goes here
> Because
> s.size > 10 # It contains escape sequences to enact colours.
> even though it only contains 6 printable characters.


> Does anyone have any alternative, or a bright idea?

s = "string".ljust(10).bold.red.on_white

?

-austin
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.10.28
* 10.50.55



1 Answer

Gavin Sinclair

10/28/2003 9:02:00 PM

0

On Wednesday, October 29, 2003, 2:54:03 AM, Austin wrote:

> On Tue, 28 Oct 2003 17:32:13 +0900, Gavin Sinclair wrote:
>> Using the 'text/highlight' package on RubyForge, you can emit coloured
>> strings to the console like so:
>> s = "string".bold.red.on_white
>> Great. Now if I want to format that using:
>> printf "%-10s goes here\n", s
>> I'm not going to get (in B&W)
>> string goes here
>> Rather
>> string goes here
>> Because
>> s.size > 10 # It contains escape sequences to enact colours.
>> even though it only contains 6 printable characters.


>> Does anyone have any alternative, or a bright idea?

> s = "string".ljust(10).bold.red.on_white

> ?


Hmmm... might get a bit hairy with some more complex formats, but I
think it might just be good enough. Thanks.

Gavin