Term:ANSIColor and negative numbers

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Term:ANSIColor and negative numbers

    Hi All

    using Term:ANSIColor - does anyone know if it's possible ( or maybe I mean
    practical) to print out negative numbers in say RED, at the same time
    ensuring the original value is retained.

    so if value is -16 the it should print 16 in RED text otherwise leave it
    alone.

    Thanks in advance

    Steve


    Steve Massey Guest

  2. Similar Questions and Discussions

    1. Pulling only negative numbers from a db
      I have a field in my db that stores both negative numbers and positive numbers. I want to sum only the negative numbers. Is there a way to do this....
    2. Negative numbers in red
      Simple really - here's hoping! I have product prices (both - and +) that work well using the code below. However, I need to have the negative...
    3. Win32::Console vs Term::ANSIColor
      HI, I am trying to print in color to command window in WIN2k, I am running my script on cmd.exe , but when I use Term:ANSIColor I am not able to...
    4. Term::ANSIColor How can I print the color directly to a printer
      I have been using Term::ANSIColor to have printed charaters on my screen, how can I direct the ANSI escaped code to a color printer directly and...
    5. What is the term for this?
      cpliu wrote: Prolonged press to bring up a menu doesn't really have one, as the standard on Mac is generally to control-click or right-click...
  3. #2

    Default Re: Term:ANSIColor and negative numbers

    On Dec 17, 2003, at 11:25 AM, Steve Massey wrote:
    > Hi All
    >
    > using Term:ANSIColor - does anyone know if it's possible ( or maybe I
    > mean
    > practical) to print out negative numbers in say RED, at the same time
    > ensuring the original value is retained.
    >
    > so if value is -16 the it should print 16 in RED text otherwise leave
    > it
    > alone.
    Sure.

    use Term::ANSIColor;

    my $value = -16;

    if ($value >= 0) { print "$value\n"; }
    else { print colored(abs($value), 'red'), "\n"; }

    Hope that helps.

    James

    James Edward Gray II Guest

  4. #3

    Default RE: Term:ANSIColor and negative numbers

    Nice one James - that does it ..!!

    something more to learn - abs


    many thanks..

    -----Original Message-----
    From: James Edward Gray II [mailto:james@grayproductions.net]
    Sent: 17 December 2003 17:35
    To: Steve Massey
    Cc: [email]beginners@perl.org[/email]
    Subject: Re: Term:ANSIColor and negative numbers


    On Dec 17, 2003, at 11:25 AM, Steve Massey wrote:
    > Hi All
    >
    > using Term:ANSIColor - does anyone know if it's possible ( or maybe I
    > mean
    > practical) to print out negative numbers in say RED, at the same time
    > ensuring the original value is retained.
    >
    > so if value is -16 the it should print 16 in RED text otherwise leave
    > it
    > alone.
    Sure.

    use Term::ANSIColor;

    my $value = -16;

    if ($value >= 0) { print "$value\n"; }
    else { print colored(abs($value), 'red'), "\n"; }

    Hope that helps.

    James


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Steve Massey Guest

  5. #4

    Default Re: Term:ANSIColor and negative numbers

    On Dec 17, 2003, at 11:42 AM, Steve Massey wrote:
    > Nice one James - that does it ..!!
    Happy to help.
    > something more to learn - abs
    perldoc -f abs
    > many thanks..
    Anytime.

    James

    James Edward Gray II Guest

  6. #5

    Default Re: Term:ANSIColor and negative numbers

    On Dec 17, 2003, at 11:41 AM, Wagner, David --- Senior Programmer
    Analyst --- WGO wrote:
    > How do you get it to actually do the color? I use both std command(
    > w2k) and older version os MKS Korn shell and all I get is numbers.
    > Never understood how one actually gets the colors etc.
    >
    > What does one need to do?
    Well, probably the most common problem is that your terminal program
    must support colored output. You can probably use something like the
    following to see if yours does:

    perl -MTerm::ANSIColor -le 'print colored("Christmas!", "red on_green")'

    Hope that helps.

    James

    James Edward Gray II Guest

  7. #6

    Default Re: Term:ANSIColor and negative numbers

    > Hi All
    >
    > using Term:ANSIColor - does anyone know if it's possible ( or maybe I mean
    > practical) to print out negative numbers in say RED, at the same time
    > ensuring the original value is retained.
    >
    > so if value is -16 the it should print 16 in RED text otherwise leave it
    > alone.
    >
    Since you asked, I say it isn't practical, but then I am incredibly
    color deficient and use a dark terminal window. So most shades of red
    are lost on me in a terminal window (obviously anyone in the truly color
    blind world, we have a support tech here who is, really wouldn't
    care).... I would advocate making it optional. Does Term::ANSIColor
    understand when a user has chosen a different font-weight for a
    particular color, anyone?

    [url]http://danconia.org[/url]

    --
    Boycott the Sugar Bowl! You couldn't pay me to watch that game.
    Wiggins D Anconia Guest

  8. #7

    Default RE: Term:ANSIColor and negative numbers

    >-----Original Message-----
    >From: Wagner, David --- Senior Programmer Analyst --- WGO
    >[mailto:David.Wagner@freight.fedex.com]
    >Sent: Thursday, 18 December 2003 4:41 AM
    >To: James Edward Gray II; Steve Massey
    >Cc: [email]beginners@perl.org[/email]
    >Subject: RE: Term:ANSIColor and negative numbers
    >
    >
    >James Edward Gray II wrote:
    >> On Dec 17, 2003, at 11:25 AM, Steve Massey wrote:
    >>
    >>> Hi All
    >>>
    >>> using Term:ANSIColor - does anyone know if it's possible ( or maybe
    >>> I mean practical) to print out negative numbers in say RED, at the
    >>> same time ensuring the original value is retained.
    >>>
    >>> so if value is -16 the it should print 16 in RED text otherwise
    >>> leave it alone.
    > How do you get it to actually do the color? I use both std
    >command( w2k) and older version os MKS Korn shell and all I get is
    >numbers. Never understood how one actually gets the colors etc.
    >
    > What does one need to do?

    I'm using perl5.08 on Win2k box, and have faced the same problem in my DOS
    prompt window. There is no color changes, but some escape sequence was
    displayed instead. If I execute the sample code provided by James, I got
    "?[31m16?[0m" displayed instead of "16" in red color.

    But I do have red colored 16 displayed properly, if execute it from cgywin's
    bash shell.

    I'm presuming it got something to do with the configuration?

    \ Wenjie Wang Guest

  9. #8

    Default Re: Term:ANSIColor and negative numbers

    (William) Wenjie Wang wrote:
    >>-----Original Message-----
    >>From: Wagner, David --- Senior Programmer Analyst --- WGO
    >>[mailto:David.Wagner@freight.fedex.com]
    >>Sent: Thursday, 18 December 2003 4:41 AM
    >>To: James Edward Gray II; Steve Massey
    >>Cc: [email]beginners@perl.org[/email]
    >>Subject: RE: Term:ANSIColor and negative numbers
    >>
    >>
    >>James Edward Gray II wrote:
    >>
    >>>On Dec 17, 2003, at 11:25 AM, Steve Massey wrote:
    >>>
    >>>
    >>>>Hi All
    >>>>
    >>>>using Term:ANSIColor - does anyone know if it's possible ( or maybe
    >>>>I mean practical) to print out negative numbers in say RED, at the
    >>>>same time ensuring the original value is retained.
    >>>>
    >>>>so if value is -16 the it should print 16 in RED text otherwise
    >>>>leave it alone.
    >>
    >> How do you get it to actually do the color? I use both std
    >>command( w2k) and older version os MKS Korn shell and all I get is
    >>numbers. Never understood how one actually gets the colors etc.
    >>
    >> What does one need to do?
    >
    >
    >
    > I'm using perl5.08 on Win2k box, and have faced the same problem in my DOS
    > prompt window. There is no color changes, but some escape sequence was
    > displayed instead. If I execute the sample code provided by James, I got
    > "?[31m16?[0m" displayed instead of "16" in red color.
    >
    > But I do have red colored 16 displayed properly, if execute it from cgywin's
    > bash shell.
    >
    > I'm presuming it got something to do with the configuration?
    I believe that you need to load ANSI.SYS in your CONFIG.SYS in order to have the escape
    sequences interpreted in a DOS session.

    --
    Andrew Gaffney

    Andrew Gaffney Guest

  10. #9

    Default Re: Term:ANSIColor and negative numbers

    Wagner, David --- Senior Programmer Analyst --- WGO wrote:
    > Andrew Gaffney wrote:
    >
    >>(William) Wenjie Wang wrote:
    >>
    >>>>-----Original Message-----
    >>>>From: Wagner, David --- Senior Programmer Analyst --- WGO
    >>>>[mailto:David.Wagner@freight.fedex.com]
    >>>>Sent: Thursday, 18 December 2003 4:41 AM
    >>>>To: James Edward Gray II; Steve Massey
    >>>>Cc: [email]beginners@perl.org[/email]
    >>>>Subject: RE: Term:ANSIColor and negative numbers
    >>>>
    >>>>
    >>>>James Edward Gray II wrote:
    >>>>
    >>>>
    >>>>>On Dec 17, 2003, at 11:25 AM, Steve Massey wrote:
    >>>>>
    >>>>>
    >>>>>
    >>>>>>Hi All
    >>>>>>
    >>>>>>using Term:ANSIColor - does anyone know if it's possible ( or
    >>>>>>maybe I mean practical) to print out negative numbers in say RED,
    >>>>>>at the same time ensuring the original value is retained.
    >>>>>>
    >>>>>>so if value is -16 the it should print 16 in RED text otherwise
    >>>>>>leave it alone.
    >>>>
    >>>> How do you get it to actually do the color? I use both std
    >>>>command( w2k) and older version os MKS Korn shell and all I get is
    >>>>numbers. Never understood how one actually gets the colors etc.
    >>>>
    >>>> What does one need to do?
    >>>
    >>>
    >>>
    >>>I'm using perl5.08 on Win2k box, and have faced the same problem in
    >>>my DOS prompt window. There is no color changes, but some escape
    >>>sequence was displayed instead. If I execute the sample code
    >>>provided by James, I got "?[31m16?[0m" displayed instead of "16" in
    >>>red color.
    >>>
    >>>But I do have red colored 16 displayed properly, if execute it from
    >>>cgywin's bash shell.
    >>>
    >>>I'm presuming it got something to do with the configuration?
    >>
    >>I believe that you need to load ANSI.SYS in your CONFIG.SYS in order
    >>to have the escape sequences interpreted in a DOS session.
    >
    > Sorry, but when you say load, what do you mean? Sorry but unsure what is necessary and I would like to see this work.
    >
    > Thanks for any input.
    Well, in Windows 98 and below, you could add the line:

    DEVICE=ANSI.SYS

    to your C:\CONFIG.SYS and it would allow the command prompt to interpret ANSI escape
    sequences. Unfortunately, I do not know the equivelant for Windows NT/2K/XP.

    --
    Andrew Gaffney

    Andrew Gaffney Guest

  11. #10

    Default Re: Term:ANSIColor and negative numbers

    On 12/18/2003 9:15 PM, Andrew Gaffney wrote:
    > Wagner, David --- Senior Programmer Analyst --- WGO wrote:
    >
    >> Andrew Gaffney wrote:
    >>
    >>> (William) Wenjie Wang wrote:
    >>>
    >>>
    >>> I believe that you need to load ANSI.SYS in your CONFIG.SYS in order
    >>> to have the escape sequences interpreted in a DOS session.
    >>
    >>
    >> Sorry, but when you say load, what do you mean? Sorry but unsure
    >> what is necessary and I would like to see this work.
    >>
    >> Thanks for any input.
    >
    >
    > Well, in Windows 98 and below, you could add the line:
    >
    > DEVICE=ANSI.SYS
    >
    > to your C:\CONFIG.SYS and it would allow the command prompt to interpret
    > ANSI escape sequences. Unfortunately, I do not know the equivelant for
    > Windows NT/2K/XP.
    >
    There is no equivelant for 2K/XP. I think there is way in NT, but don't
    recall the specifics.

    Randy.


    Randy W. Sims Guest

  12. #11

    Default Re: Term:ANSIColor and negative numbers



    [email]agaffney@skylineaero.com[/email] wrote:
    > Well, in Windows 98 and below, you could add the line:
    >
    > DEVICE=ANSI.SYS
    >
    > to your C:\CONFIG.SYS and it would allow the command prompt to
    > interpret ANSI escape sequences. Unfortunately, I do not know the
    > equivelant for Windows NT/2K/XP.
    Ahh, A Golden Oldie for sure!

    Your Friendly Neighborhood DBA,

    Chuck

    Chuck Fox Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139