Test whether a given `std::ostream` object refers to a terminal.
| 854 | //! Test whether a given `std::ostream` object refers to |
| 855 | //! a terminal. |
| 856 | inline |
| 857 | bool is_atty(const std::ostream& stream) |
| 858 | { |
| 859 | FILE* std_stream = get_standard_stream(stream); |
| 860 | |
| 861 | // Unfortunately, fileno() ends with segmentation fault |
| 862 | // if invalid file descriptor is passed. So we need to |
| 863 | // handle this case gracefully and assume it's not a tty |
| 864 | // if standard stream is not detected, and 0 is returned. |
| 865 | if (!std_stream) |
| 866 | return false; |
| 867 | |
| 868 | #if defined(TERMCOLOR_TARGET_POSIX) |
| 869 | return ::isatty(fileno(std_stream)); |
| 870 | #elif defined(TERMCOLOR_TARGET_WINDOWS) |
| 871 | return ::_isatty(_fileno(std_stream)); |
| 872 | #else |
| 873 | return false; |
| 874 | #endif |
| 875 | } |
| 876 | |
| 877 | #if defined(TERMCOLOR_TARGET_WINDOWS) |
| 878 | //! Change Windows Terminal colors attribute. If some |
no test coverage detected