14

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.

3 Answers3

22

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.

Kilian Foth
  • 107,706
  • 45
  • 295
  • 310
  • 5
    This is the functionality of `ls` (the `ls --color` option is required to turn it on). –  Nov 01 '13 at 18:59
  • @MichaelT: Really? I guess it depends on the distribution you use. The output (almost) always has colour and I never specify `--color`. – FrustratedWithFormsDesigner Nov 01 '13 at 19:18
  • 1
    @FrustratedWithFormsDesigner BSD flavor. `/bin/ls` is plain, `/bin/ls -G` is colored (though if you have CLICOLOR defined in the environment, that option acts as default on). In [gnu influenced distributions](http://www.gnu.org/software/coreutils/manual/html_node/General-output-formatting.html), one sees `--color` and its associated environment variables. –  Nov 01 '13 at 19:32
  • 1
    Great answer to "Should color be mandatory or not", less so for "when is it appropriate" :) – Michael Durrant Nov 01 '13 at 21:37
  • 3
    @FrustratedWithFormsDesigner On ubuntu, for example, `alias ls='ls --color=auto'` comes in the default `.bashrc` (or if it doesn't anymore, it did somewhere around 8.04 give or take a year, and I've just carried my .bashrc across installations) – Izkata Nov 02 '13 at 03:30
  • How common are terminals that don't support colours these days? – Pointless One Nov 06 '13 at 17:28
9

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.

Michael Durrant
  • 13,101
  • 5
  • 34
  • 60
5

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.