Re: How to print colored text to a linux terminal?

From: _at_'>o2.pl (_at_')
Date: 06/03/04

  • Next message: Rolf Magnus: "Re: Http Client Side Programming --- Any Libraries Avl."
    Date: Thu, 03 Jun 2004 13:53:09 +0200
    
    

    > On a sunny day (Wed, 02 Jun 2004 19:55:55 +0000) it happened seesawman@163.com
    > wrote in <40BE30CB.5692A265@163.com>:
    >
    >
    >>Could anyone tell me how i can print colored text to a linux text-mode
    >>terminal, just like ls command does.
    >
    > This makes use of the ANSI sequences
    >
    > Try this for example:
    > char *text;
    > int color;
    > printf("\33[01;%dm%s\33[00m", color, text);/* \33 is escape */
    >
    > For the colors do some searching in www.google.com perhaps.
    > JP

    It will work, but it is better to use terminfo or termcap database
    rather than escape codes. It will problems on other terminals. Of course
      for small programs it isn't so important.


  • Next message: Rolf Magnus: "Re: Http Client Side Programming --- Any Libraries Avl."

    Relevant Pages

    • Re: line printer settings
      ... >>I also used the lp command in order to change the cpi, ... > The lp program is supposed to use the terminfo entry ... > $ infocmp ibmxl | grep cpi ... > $ infocmp ibmproprinter | grep lpi ...
      (comp.unix.solaris)
    • Re: terminal command line weirdness
      ... > statements that don't use all the space on the right of the command line ... This sounds like a traditional terminfo problem. ... james@ | In the Royal Air Force a landing's OK, ...
      (Fedora)
    • Re: terminal problems.
      ... I missed the bit about the "command line" earlier. ... Exceed works on one (Alpha), not the other (Linux). ... If both boxes are using terminfo databases, then a good start would be ...
      (comp.databases.ingres)
    • Re: null bytes after ANSI sequences in color ls output
      ... I normally pipe my output to 'less -R' so ANSI sequences pass through while ... other control characters are converted to visible ones. ... It's possible that an application could be sending padding characters ... If your terminal description came in part from terminfo, ...
      (freebsd-questions)
    • Re: Control N
      ... generalized command to reset the display needs to do a lot more ... that alias will send the correct sequences... ... /only/ if the TERMINFO database is correctly configured. ...
      (comp.unix.questions)