cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
iostream_initializer.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
11
16#include "cpp-terminal/tty.hpp"
17
18#include <cstddef>
19#include <iostream>
21
23try
24{
25 if(0 == m_counter)
26 {
27 static const std::ios_base::Init iostreams_init; // Init std::cout etc...
28 static const Term::TerminalInitializer terminal_init; // Make sure terminal is set up.
33 if(is_stdin_a_tty()) { std::cin.rdbuf(Term::cin.rdbuf()); }
34 }
35 ++m_counter;
36}
37catch(...)
38{
40}
41
43try
44{
45 --m_counter;
46 if(0 == m_counter)
47 {
48 (&Term::cout)->~TOstream();
49 (&Term::cerr)->~TOstream();
50 (&Term::clog)->~TOstream();
51 (&Term::cin)->~TIstream();
52 }
53}
54catch(...)
55{
57}
std::streambuf * rdbuf() const
Definition stream.cpp:16
TOstream & clog
Definition iostream.cpp:23
TOstream & cout
Definition iostream.cpp:22
TOstream & cerr
Definition iostream.cpp:24
TIstream & cin
Definition iostream.cpp:25
bool is_stdin_a_tty()
Check if stdin is a tty.
Definition tty.cpp:32