Question

Currently I have a command-line application in C called btcwatch. It has a -C option that it can receive as an argument that compares the current price of Bitcoin with a price that was stored beforehand with -S. Example output with this option is:

$ btcwatch -vC  # -v = verbose
buy: UP $ 32.000000 USD (100.000000 -> 132.000000)
sell: UP $ 16.000000 USD (100.000000 -> 116.000000)

The dilemma is whether to use colour for the UP or DOWN string (green and red, respectively). Most command-line applications I know of (apart from git) stay away from colour in their output. In my desire for btcwatch to look and be quite "standard" (use of getopt, Makefiles, etc), I'm not sure if colour would look out of place in this situation.

Was it helpful?

Solution

The appropriate thing to do is to make the coloring optional, default to "off" and control it via a command-line flag. That way, people who don't like it or whose terminal doesn't support it aren't affected, people who like it can use it, and people who really, really like it can define an alias or shortcut to predefine the option. Everybody's happy.

OTHER TIPS

I would consider it appropriate to use color when:

  • There are 'groups' of items and color groups will help visually group the items.

  • There are set(s) of 'label:value' fields and you want the labels (or values) to stand out.

  • There are items that would benefit from being shown in red/green, e.g. stop/go, good/bad, etc.

  • Most of the information is background but one key item should stand out.

One other major factor to consider is that coloring, depending on platform, can add character escape sequences. For builds on those platforms, If the current/default mode is to output colour, it is customary to detect if the program output is a PIPE and stripping colour if that is the case.

This is so that the color escape sequences do not throw off downstream programs that read it's output.

Licensed under: CC-BY-SA with attribution
scroll top