예제 #1
0
		//! Test whether a given `std::ostream` object refers to
		//! a terminal.
		inline
			bool is_atty(const std::ostream& stream)
		{
			FILE* std_stream = get_standard_stream(stream);

#if defined(OS_MACOS) || defined(OS_LINUX)
			return ::isatty(fileno(std_stream));
#elif defined(OS_WINDOWS)
			return ::_isatty(_fileno(std_stream));
#endif
		}
예제 #2
0
        //! Test whether a given `std::ostream` object refers to
        //! a terminal.
        inline
        bool is_atty(const std::ostream& stream)
        {
            FILE* std_stream = get_standard_stream(stream);

            // Unfortunately, fileno() ends with segmentation fault
            // if invalid file descriptor is passed. So we need to
            // handle this case gracefully and assume it's not a tty
            // if standard stream is not detected, and 0 is returned.
            if (!std_stream)
                return false;

        #if defined(TERMCOLOR_OS_MACOS) || defined(TERMCOLOR_OS_LINUX)
            return ::isatty(fileno(std_stream));
        #elif defined(TERMCOLOR_OS_WINDOWS)
            return ::_isatty(_fileno(std_stream));
        #endif
        }