-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / cpp-linterRun clang-format on cpp-terminal/private/signals.cpp
|
||
* 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 GitHub Actions / windows-2019 clang-11.1.0 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-11.1.0 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-12.0.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-11.1.0 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-12.0.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-12.0.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-11.1.0 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.2.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-12.0.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.2.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.2.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.2.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.2 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.2 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++14)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++20)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.1 (c++11)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.1 (c++17)
Check warning on line 25 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++17)
|
||
} | ||
|
||
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 GitHub Actions / windows-2019 clang-13.0.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-12 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-13 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-13.0.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 gcc-14 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-15.0.2 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / windows-2019 clang-14.0.6 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.4.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.3.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.2 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.2 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.2 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.0.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-14.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-13 xcode-15.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++14)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-12 xcode-13.3.1 (c++20)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.0.1 (c++17)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-15.1 (c++11)
Check warning on line 154 in cpp-terminal/private/signals.cpp GitHub Actions / macos-14 xcode-14.3.1 (c++17)
|
||
old = std::signal(sign, m_han[sign]); | ||
term.clean(); | ||
std::raise(sign); | ||
} | ||
} |
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 |