Applications should have a global --color option, with the values always, auto (default) and never. If this is specified as always or never, applications must enable or disable colors respectively.
Otherwise, if one of a number of environment variables is specified, applications should do what it says.1
Otherwise, if the output stream (stdout or stderr) is a pipe, applications must disable colors. (Each output stream must be evaluated separately. For example, if stdout is a pipe but stderr isn't, applications must disable colors on stdout but may enable them on stderr.)
Otherwise, applications may enable colors.
2 and 3 are covered by the supports-color Rust library. The exact set of environment variables is too complicated to describe here. See the source code of supports-color for a full list.
It must be possible to disable colors. Some users's terminals may have broken color support; in other cases, pipe detection may not work as expected.
General recommendations These rules apply to all command-line programs, not just Rust ones.
Applications should have a global --color option, with the values always, auto (default) and never. If this is specified as always or never, applications must enable or disable colors respectively. Otherwise, if one of a number of environment variables is specified, applications should do what it says.1 Otherwise, if the output stream (stdout or stderr) is a pipe, applications must disable colors. (Each output stream must be evaluated separately. For example, if stdout is a pipe but stderr isn't, applications must disable colors on stdout but may enable them on stderr.) Otherwise, applications may enable colors. 2 and 3 are covered by the supports-color Rust library. The exact set of environment variables is too complicated to describe here. See the source code of supports-color for a full list.
It must be possible to disable colors. Some users's terminals may have broken color support; in other cases, pipe detection may not work as expected.