Skip to content

Commit

Permalink
Signal_handler to clean the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
flagarde committed Oct 31, 2024
1 parent 808d1be commit 25feddb
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 23 deletions.
1 change: 0 additions & 1 deletion cpp-terminal/iostream_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <cstddef>
#include <iostream>

std::size_t Term::IOStreamInitializer::m_counter{0};

Term::IOStreamInitializer::IOStreamInitializer() noexcept
Expand Down
1 change: 1 addition & 0 deletions cpp-terminal/private/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target_sources(cpp-terminal-private INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/env.cpp>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/blocking_queue.cpp>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sigwinch.cpp>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/signals.cpp>
)
target_link_libraries(cpp-terminal-private INTERFACE Warnings::Warnings Threads::Threads)
target_compile_options(cpp-terminal-private INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
Expand Down
159 changes: 159 additions & 0 deletions cpp-terminal/private/signals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*

Check notice on line 1 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on cpp-terminal/private/signals.cpp

File cpp-terminal/private/signals.cpp does not conform to Custom style guidelines. (lines 30, 34, 37, 40, 43, 66, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148)
* cpp-terminal
* C++ library for writing multi-platform terminal applications.
*
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
*
* SPDX-License-Identifier: MIT
*/

#include "cpp-terminal/private/signals.hpp"

#include "cpp-terminal/terminal.hpp"

#include <algorithm>
#include <csignal>

#ifndef NSIG
#define NSIG (_SIGMAX + 1) /* For QNX */
#endif

const std::size_t Term::Private::Signals::m_signals_number{NSIG - 1};

void Term::Private::Signals::setHandler(const sighandler_t& handler) noexcept
{
for(std::size_t signal = 0; signal != m_signals_number; ++signal) { sighandler_t hand = std::signal(signal, handler); }

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-11.1.0 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-11.1.0 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-12.0.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-11.1.0 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-12.0.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-12.0.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-11.1.0 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.2.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-12.0.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.2.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.2.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.2.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.2 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.2 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++14)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++20)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.1 (c++11)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++17)

unused variable 'hand' [-Wunused-variable]

Check warning on line 25 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++17)

unused variable 'hand' [-Wunused-variable]
}

Term::Private::Signals::Signals(std::vector<sighandler_t>& m_han) noexcept
{
const static std::vector<int> ignore{
#if defined(SIGCONT)
SIGCONT,
#endif
#if defined(SIGSTOP)
SIGSTOP,
#endif
#if defined(SIGTSTP)
SIGTSTP,
#endif
#if defined(SIGTTIN)
SIGTTIN,
#endif
#if defined(SIGTTOU)
SIGTTOU,
#endif
};
m_han.reserve(m_signals_number);
for(std::size_t signal = 0; signal != m_signals_number; ++signal)
{
//if(std::find(ignore.begin(),ignore.end(),signal)==ignore.end())
//{
sighandler_t old = std::signal(signal, SIG_DFL);
//sighandler_t dumb=std::signal(signal, old);
m_han.push_back(old);
//}
//else
//{
// std::signal(signal, SIG_IGN);
// m_han.push_back(std::signal(signal, SIG_IGN));
// }
}
}

void Term::Private::Signals::reset_and_raise(int sign, std::vector<sighandler_t>& m_han, Term::Terminal& term) noexcept
{
const static std::vector<int> termin{
#if defined(SIGHUP)
SIGHUP,
#endif
#if defined(SIGHUP)
SIGINT,
#endif
#if defined(SIGQUIT)
SIGQUIT,
#endif
#if defined(SIGQUIT)
SIGILL,
#endif
#if defined(SIGTRAP)
SIGTRAP,
#endif
#if defined(SIGTRAP)
SIGABRT,
#endif
#if defined(SIGIOT)
SIGIOT,
#endif
#if defined(SIGBUS)
SIGBUS,
#endif
#if defined(SIGBUS)
SIGFPE,
#endif
#if defined(SIGKILL)
SIGKILL,
#endif
#if defined(SIGUSR1)
SIGUSR1,
#endif
#if defined(SIGSEGV)
SIGSEGV,
#endif
#if defined(SIGUSR2)
SIGUSR2,
#endif
#if defined(SIGUSR2)
SIGPIPE,
#endif
#if defined(SIGALRM)
SIGALRM,
#endif
#if defined(SIGSTKFLT)
SIGSTKFLT,
#endif
#if defined(SIGCONT)
SIGCONT,
#endif
#if defined(SIGXCPU)
SIGXCPU,
#endif
#if defined(SIGXFSZ)
SIGXFSZ,
#endif
#if defined(SIGVTALRM)
SIGVTALRM,
#endif
#if defined(SIGPROF)
SIGPROF,
#endif
#if defined(SIGPROF)
SIGIO,
#endif
#if defined(SIGPOLL)
SIGPOLL,
#endif
#if defined(SIGPWR)
SIGPWR,
#endif
#if defined(SIGSYS)
SIGSYS,
#endif
#if defined(SIGUNUSED)
SIGUNUSED,
#endif
#if defined(SIGUNUSED)
SIGUNUSED,
#endif
#if defined(SIGTERM)
SIGTERM
#endif
};
if(std::find(termin.begin(), termin.end(), sign) != termin.end())
{
sighandler_t old = std::signal(sign, m_han[sign]);

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-12 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-13 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-13.0.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 gcc-14 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-15.0.2 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / windows-2019 clang-14.0.6 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.4.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.3.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.2 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.2 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.2 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-14.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++14)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-12 xcode-13.3.1 (c++20)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.0.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-15.1 (c++11)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-14 xcode-14.3.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]

Check warning on line 154 in cpp-terminal/private/signals.cpp

View workflow job for this annotation

GitHub Actions / macos-13 xcode-15.0.1 (c++17)

variable 'old' set but not used [-Wunused-but-set-variable]
old = std::signal(sign, m_han[sign]);
term.clean();
std::raise(sign);
}
}
33 changes: 33 additions & 0 deletions cpp-terminal/private/signals.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* cpp-terminal
* C++ library for writing multi-platform terminal applications.
*
* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
*
* SPDX-License-Identifier: MIT
*/

#pragma once
#include <cstddef>
#include <vector>

using sighandler_t = void (*)(int);

namespace Term
{
class Terminal;
namespace Private
{
class Signals
{
public:
Signals(std::vector<sighandler_t>& m_han) noexcept;
~Signals() noexcept {}
void setHandler(const sighandler_t& handler) noexcept;
static void reset_and_raise(int sign, std::vector<sighandler_t>& m_han, Term::Terminal&) noexcept;

private:
const static std::size_t m_signals_number;
};
} // namespace Private
} // namespace Term
3 changes: 2 additions & 1 deletion cpp-terminal/private/terminal_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cpp-terminal/private/env.hpp"
#include "cpp-terminal/private/exception.hpp"
#include "cpp-terminal/private/file.hpp"
//#include "cpp-terminal/private/signals.hpp"
#include "cpp-terminal/private/sigwinch.hpp"
#include "cpp-terminal/terminal.hpp"

Expand Down Expand Up @@ -224,7 +225,7 @@ void Term::Terminal::setMode() const
unsetFocusEvents();
}
if(m_options.has(Option::NoSignalKeys)) { send.c_lflag &= ~static_cast<std::size_t>(ISIG); } //FIXME need others flags !
else if(m_options.has(Option::SignalKeys)) { send.c_lflag |= ISIG; }
if(m_options.has(Option::SignalKeys)) { send.c_lflag |= ISIG; }
Term::Private::Errno().check_if(tcsetattr(Private::out.fd(), TCSAFLUSH, &send) == -1).throw_exception("tcsetattr(Private::out.fd(), TCSAFLUSH, &send)");
}
#endif
Expand Down
15 changes: 10 additions & 5 deletions cpp-terminal/terminal_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ catch(...)
ExceptionHandler(Private::ExceptionDestination::StdErr);
}

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 win32 (c++11)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 x64 (c++14)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 win32 (c++11)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 x64 (c++17)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 win32 (c++17)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 win32 (c++17)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 win32 (c++14)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 x64 (c++17)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 win32 (c++20)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 win32 (c++20)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 win32 (c++14)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 x64 (c++20)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2022 x64 (c++11)

'Term::Terminal::Terminal': function assumed not to throw an exception but does [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 x64 (c++20)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 x64 (c++14)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Check warning on line 32 in cpp-terminal/terminal_impl.cpp

View workflow job for this annotation

GitHub Actions / msvc2019 x64 (c++11)

'Term::Terminal::Terminal': function assumed not to throw an exception but doesD:\a\cpp-terminal\cpp-terminal\cpp-terminal\terminal_impl.cpp(32,1): note: __declspec(nothrow), throw(), noexcept(true), or noexcept was specified on the function [D:\a\cpp-terminal\cpp-terminal\build\cpp-terminal\cpp-terminal.vcxproj]

Term::Terminal::~Terminal() noexcept
try
void Term::Terminal::clean()
{
if(getOptions().has(Option::ClearScreen)) { Term::Private::out.write(clear_buffer() + style(Style::Reset) + cursor_move(1, 1) + screen_load()); }
unsetFocusEvents();
unsetMouseEvents();
if(getOptions().has(Option::NoCursor)) { Term::Private::out.write(cursor_on()); }
if(getOptions().has(Option::ClearScreen)) { Term::Private::out.write(clear_buffer() + style(Style::Reset) + cursor_move(1, 1) + screen_load()); }
set_unset_utf8();
store_and_restore();
unsetFocusEvents();
unsetMouseEvents();
}

Term::Terminal::~Terminal() noexcept
try
{
clean();
}
catch(...)
{
Expand Down
3 changes: 3 additions & 0 deletions cpp-terminal/terminal_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

#include "cpp-terminal/options.hpp"
#include "cpp-terminal/private/signals.hpp"
#include "cpp-terminal/terminal_initializer.hpp"

#include <cstddef>
Expand All @@ -20,6 +21,7 @@ namespace Term
class Terminal
{
public:
friend class Private::Signals;
~Terminal() noexcept;
Terminal() noexcept;
Terminal(const Terminal&) = delete;
Expand Down Expand Up @@ -55,6 +57,7 @@ class Terminal

static void set_unset_utf8();
Term::Options m_options;
void clean();
};

} // namespace Term
5 changes: 5 additions & 0 deletions cpp-terminal/terminal_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "cpp-terminal/private/exception.hpp"
#include "cpp-terminal/private/file_initializer.hpp"
#include "cpp-terminal/private/signals.hpp"
#include "cpp-terminal/terminal.hpp"

#include <new>
Expand All @@ -23,7 +24,11 @@ try
if(0 == m_counter)
{
static const Private::FileInitializer files_init;
static std::vector<sighandler_t> m_handlers;
new(&Term::terminal) Terminal();
static Term::Private::Signals signals(m_handlers);
sighandler_t handler = [](int signum) { Term::Private::Signals::reset_and_raise(signum, m_handlers, Term::terminal); };
signals.setHandler(handler);
}
++m_counter;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cpp-terminal/input.hpp"
#include "cpp-terminal/iostream.hpp"
#include "cpp-terminal/key.hpp"
#include "cpp-terminal/options.hpp"
#include "cpp-terminal/screen.hpp"
#include "cpp-terminal/style.hpp"
#include "cpp-terminal/terminal.hpp"
Expand Down Expand Up @@ -93,7 +94,7 @@ int main()
try
{
// check if the terminal is capable of handling input
Term::terminal.setOptions(Term::Option::ClearScreen, Term::Option::NoSignalKeys, Term::Option::NoCursor, Term::Option::Raw);
Term::terminal.setOptions(Term::Option::Raw, Term::Option::NoSignalKeys, Term::Option::ClearScreen, Term::Option::NoCursor);
if(!Term::is_stdin_a_tty()) { throw Term::Exception("The terminal is not attached to a TTY and therefore can't catch user input. Exiting..."); }
Term::Screen term_size = Term::screen_size();
std::size_t pos{5};
Expand Down Expand Up @@ -141,8 +142,7 @@ int main()
need_to_render = true;
break;
case Term::Key::q:
case Term::Key::Esc:
case Term::Key::Ctrl_C: on = false;
case Term::Key::Esc: on = false; break;
default: break;
}
break;
Expand Down
47 changes: 34 additions & 13 deletions examples/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,46 @@
*/

#include "cpp-terminal/iostream.hpp"
#include "cpp-terminal/options.hpp"
#include "cpp-terminal/terminal.hpp"

#include <csignal>
#include <fstream>
#include <iostream>

int main()
{
std::at_quick_exit(
[]()
{
std::cout << "Unhandled exception\n" << std::flush;
//std::abort();
});
std::set_terminate(
[]()
{
std::cout << "Unhandled exception\n" << std::flush;
//std::abort();
});
Term::terminal.setOptions(Term::Option::Raw, Term::Option::SignalKeys);
Term::terminal.setOptions(Term::Option::Raw, Term::Option::NoSignalKeys, Term::Option::ClearScreen);
std::signal(SIGINT,
[](int sig)
{
std::ofstream outfile("cpp_terminal_signal.txt");
outfile << "my text here!" << std::endl;
outfile.close();
std::exit(1);
});
std::cout << "This is printed with std::cout with std::end (1)" << std::endl;
std::clog << "This is printed with std::clog with std::end (2)" << std::endl;
std::cerr << "This is printed with std::cerr with std::end (3)" << std::endl;

Term::cout << "This is printed with Term::cout with std::end (4)" << std::endl;
Term::clog << "This is printed with Term::clog with std::end (5)" << std::endl;
Term::cerr << "This is printed with Term::cerr with std::end (6)" << std::endl;

std::cout << "This is printed with std::cout with flush() (7)\n" << std::flush;
std::clog << "This is printed with std::clog with flush() (8)\n" << std::flush;
std::cerr << "This is printed with std::cerr with flush() (9)\n" << std::flush;

Term::cout << "This is printed with Term::cout with flush() (10)\n" << std::flush;
Term::clog << "This is printed with Term::clog with flush() (11)\n" << std::flush;
Term::cerr << "This is printed with Term::cerr with flush() (12)\n" << std::flush;

std::cout << "This is printed (13) ";
std::cout << "with std::cout (13)";
std::clog << "This is printed (14) ";
std::clog << "with std::clog (14)";
std::cerr << "This is printed (15) ";
std::cerr << "with std::cerr (15)";
while(true) {}
return 0;
}

0 comments on commit 25feddb

Please sign in to comment.