views:

52

answers:

2

I have several question:

  1. If there is an error which has to be displayed to the client - It is a good thing to use STDERR stream instead of STDOUT? Or is it a trivial issue?

  2. I want to add color support to output messages of this utility. Do I have to use some environment-tolerant framework for that?(it can be 256 color mode and "pure" one). Or how to make it tolerant?

  3. I'm afraid to add colors to the output because clients may redirect output to log file. Can it potentially "break" anything because of that?

Please help me to build this utility in UNIX-way(Do one thing and do it well).

+4  A: 

STDERR is better than STDOUT for errors for a couple of reasons. Redirecting the output won't hide the errors from you. You can prevent warnings from mixing with the output which makes it easier to parse/process in some cases.

You may want to look into the curses library which should support the ANSI color sets.

Utilities like ls will detect if their output is being redirected and drop the color codes so that log files, etc. don't get horked up. You should do the same.

Amardeep
+3  A: 

Use STDERR. As for the colors, your concern can be alleviated by checking if the output is a tty before printing colors to it. During initialization, have a check that enables or disables colors on the fly. It's also good practice to have a --color=[on|off|auto] flag that a user can pass to select one explicitly.

Daenyth