cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
tty.cpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
10#include <cstdio>
11
12#ifdef _WIN32
13 #include <io.h>
14#else
15 #include <unistd.h>
16#endif
17
18#include "cpp-terminal/tty.hpp"
19
20namespace
21{
22bool is_a_tty(const FILE* fd)
23{
24#ifdef _WIN32
25 return static_cast<bool>(_isatty(_fileno(const_cast<FILE*>(fd))));
26#else
27 return ::isatty(::fileno(const_cast<FILE*>(fd)));
28#endif
29}
30} // namespace
31
32bool Term::is_stdin_a_tty() { return ::is_a_tty(stdin); }
33
34bool Term::is_stdout_a_tty() { return ::is_a_tty(stdout); }
35
36bool Term::is_stderr_a_tty() { return ::is_a_tty(stderr); }
bool is_stdout_a_tty()
Check if stdout is a tty.
Definition tty.cpp:34
bool is_stderr_a_tty()
Check if stderr is a tty.
Definition tty.cpp:36
bool is_stdin_a_tty()
Check if stdin is a tty.
Definition tty.cpp:32