One way to solve this nicely, that seems to be getting more common, is to use `isatty()` to check if the output is a terminal and if so print with decorations, otherwise leave them away.
`ls` for example will output unprintable characters, even just space, in quoted form on a terminal:
$ touch 'foo bar'
$ ls
'foo bar'
But when redirected, it will output the raw value: $ ls | cat -
foo bar