kirb / theos

Unified cross-platform iPhone Makefile system
https://github.com/kirb/theos/wiki
Other
42 stars 7 forks source link

Don't use escape sequences when stdout isn't a tty #11

Open kirb opened 9 years ago

kirb commented 9 years ago

Tricky to solve, maybe even impossible, because all the solutions I've seen execute the check in a subshell ($(shell …)), and, well, that's a subshell, its output isn't going to be a tty.

Tried:

_THEOS_IS_INTERACTIVE_SHELL = $(shell [ -t 1 ] && echo 1)  # always false
_THEOS_IS_INTERACTIVE_SHELL = $(shell [ -t 0 ] && echo 1)  # works, but only if piping something on stdin (very unlikely)
all::
    @-[ -t 1 ]
_THEOS_IS_INTERACTIVE_SHELL = $?  # separate command from the one above, so $? is 0
INTERACTIVE := $(shell [ -t 0 ] && echo 1)

ifdef INTERACTIVE
_THEOS_IS_INTERACTIVE_SHELL = 1
else
_THEOS_IS_INTERACTIVE_SHELL = 0
endif

See also (didn't work, at least on OS X with GNU make)