Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help: Characters with colors

Reply
Thread Tools

Help: Characters with colors

 
 
Amy Lee
Guest
Posts: n/a
 
      08-20-2008
Hello,

How to modify the color of characters when I display them?

Thank you very much~

Regards,

Amy
 
Reply With Quote
 
 
 
 
magloca
Guest
Posts: n/a
 
      08-20-2008
Amy Lee @ Wednesday 20 August 2008 15:00:

> Hello,
>
> How to modify the color of characters when I display them?
>
> Thank you very much~
>
> Regards,
>
> Amy


In a terminal? Term::ANSIColor. Somewhere else? You'll have to be more
specific.

m.
 
Reply With Quote
 
 
 
 
Amy Lee
Guest
Posts: n/a
 
      08-20-2008
On Wed, 20 Aug 2008 15:16:36 +0200, magloca wrote:

> Amy Lee @ Wednesday 20 August 2008 15:00:
>
>> Hello,
>>
>> How to modify the color of characters when I display them?
>>
>> Thank you very much~
>>
>> Regards,
>>
>> Amy

>
> In a terminal? Term::ANSIColor. Somewhere else? You'll have to be more
> specific.
>
> m.

Yes, thank you very much.

Amy
 
Reply With Quote
 
Amy Lee
Guest
Posts: n/a
 
      08-20-2008
On Wed, 20 Aug 2008 21:49:44 +0800, Amy Lee wrote:

> On Wed, 20 Aug 2008 15:16:36 +0200, magloca wrote:
>
>> Amy Lee @ Wednesday 20 August 2008 15:00:
>>
>>> Hello,
>>>
>>> How to modify the color of characters when I display them?
>>>
>>> Thank you very much~
>>>
>>> Regards,
>>>
>>> Amy

>>
>> In a terminal? Term::ANSIColor. Somewhere else? You'll have to be more
>> specific.
>>
>> m.

> Yes, thank you very much.
>
> Amy

Anyway, there's something I feel a little confused. I find that this
module is for 'print', when I use it on 'die' function it's still working
but will output a line like this:

at ./hwinfo.pl line 17, <KER_VER> line 1.

My codes:

use strict;
use warnings;
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;

open KER_VER, "<", "/root/version";
while (<KER_VER>)
{
unless (/\s+2.4.\d+/)
{
die BOLD RED "Your kernel version is not 2.4.x.\n"
}
}


I hope clean this internal output by perl, how could I do that?

Thank you very much~

Amy
 
Reply With Quote
 
Lars Eighner
Guest
Posts: n/a
 
      08-20-2008
In our last episode, <(E-Mail Removed)>, the lovely
and talented Amy Lee broadcast on comp.lang.perl.misc:

> open KER_VER, "<", "/root/version";
> while (<KER_VER>)
> {
> unless (/\s+2.4.\d+/)
> {
> die BOLD RED "Your kernel version is not 2.4.x.\n"
> }
> }



> I hope clean this internal output by perl, how could I do that?


> Thank you very much~


You can write ansi codes directly, but in spite of ansi being
more or less a standard, there are serious portability problems.
Some terminals are not ansi capable and others may be quirky.

--
Lars Eighner <http://larseighner.com/> http://www.velocityreviews.com/forums/(E-Mail Removed)
"I believe in God and I believe in free markets,"
-Kenneth Lay, CEO for the now defunct Enron, whose loss of some 50
billion dollars represents the largest corporate bankruptcy in the
history of the US.
 
Reply With Quote
 
Jrgen Exner
Guest
Posts: n/a
 
      08-20-2008
Amy Lee <(E-Mail Removed)> wrote:
>How to modify the color of characters when I display them?


That depends _VERY_ on much how and where you display them. "perldoc -q
color"
How do I print something out in color?
may help get you started.

jue
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      08-20-2008
Amy Lee <(E-Mail Removed)> writes:

> How to modify the color of characters when I display them?


It depends on how you're displaying them. Are you writing a web app, a
GUI app, an app that runs in a terminal window, etc.?

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
 
Reply With Quote
 
Amy Lee
Guest
Posts: n/a
 
      08-20-2008
On Wed, 20 Aug 2008 14:40:47 +0000, Jrgen Exner wrote:

> Amy Lee <(E-Mail Removed)> wrote:
>>How to modify the color of characters when I display them?

>
> That depends _VERY_ on much how and where you display them. "perldoc -q
> color"
> How do I print something out in color?
> may help get you started.
>
> jue

Thank you very much. Anyway, when I want to search some keywords, could I
use "perldoc -q <keyword>"?

Best Regards,

Amy
 
Reply With Quote
 
Amy Lee
Guest
Posts: n/a
 
      08-20-2008
On Wed, 20 Aug 2008 14:40:19 +0000, Lars Eighner wrote:

> In our last episode, <(E-Mail Removed)>, the lovely
> and talented Amy Lee broadcast on comp.lang.perl.misc:
>
>> open KER_VER, "<", "/root/version";
>> while (<KER_VER>)
>> {
>> unless (/\s+2.4.\d+/)
>> {
>> die BOLD RED "Your kernel version is not 2.4.x.\n"
>> }
>> }

>
>
>> I hope clean this internal output by perl, how could I do that?

>
>> Thank you very much~

>
> You can write ansi codes directly, but in spite of ansi being
> more or less a standard, there are serious portability problems.
> Some terminals are not ansi capable and others may be quirky.

Thank you, but it seems that it's for 'print', not for 'die'. How do I
handle with color when I use 'die'?

Regards,

Amy
 
Reply With Quote
 
Brian Helterlilne
Guest
Posts: n/a
 
      08-20-2008
Amy Lee wrote:
> On Wed, 20 Aug 2008 14:40:19 +0000, Lars Eighner wrote:
>
>> In our last episode, <(E-Mail Removed)>, the lovely
>> and talented Amy Lee broadcast on comp.lang.perl.misc:
>>
>>> open KER_VER, "<", "/root/version";
>>> while (<KER_VER>)
>>> {
>>> unless (/\s+2.4.\d+/)
>>> {
>>> die BOLD RED "Your kernel version is not 2.4.x.\n"
>>> }
>>> }

>>
>>> I hope clean this internal output by perl, how could I do that?
>>> Thank you very much~

>> You can write ansi codes directly, but in spite of ansi being
>> more or less a standard, there are serious portability problems.
>> Some terminals are not ansi capable and others may be quirky.

> Thank you, but it seems that it's for 'print', not for 'die'. How do I
> handle with color when I use 'die'?


Read the documentation for the other interface - colored(). It returns a
string with the codes embedded.

die colored( "Your kernel version is not 2.4.x.\n", 'bold red' );

--
-brian
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any library that can convert RGB colors to ANSI colors? ZelluX Python 3 12-01-2008 11:08 AM
TreeNode colors come from anchor colors AAaron123 ASP .Net 1 08-07-2008 07:56 PM
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM
Convert Raw Text Escaped Characters to Characters nicholas.wakefield@gmail.com Java 2 07-11-2005 09:17 PM
help-> xslt transformation to pdf (chinese characters changed to # characters) omegaman XML 1 09-21-2004 10:44 PM



Advertisments