File tree Expand file tree Collapse file tree 4 files changed +17
-13
lines changed Expand file tree Collapse file tree 4 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 9
9
10
10
#include " cpp-terminal/private/signals.hpp"
11
11
12
- #include " cpp-terminal/terminal .hpp"
12
+ #include " cpp-terminal/terminal_impl .hpp"
13
13
#include " signals.hpp"
14
14
15
15
#include < algorithm>
@@ -36,10 +36,7 @@ static BOOL WINAPI consoleHandler(DWORD signal)
36
36
}
37
37
#endif
38
38
39
- void Term::Private::Signals::clean_terminal () noexcept
40
- {
41
- Term::terminal.clean ();
42
- }
39
+ void Term::Private::Signals::clean_terminal () noexcept { const_cast <Term::Terminal*>(m_term)->clean (); }
43
40
44
41
const std::size_t Term::Private::Signals::m_signals_number{NSIG - 1 };
45
42
@@ -58,8 +55,11 @@ void Term::Private::Signals::setHandler(const sighandler_t& handler) noexcept
58
55
#endif
59
56
}
60
57
61
- Term::Private::Signals::Signals () noexcept
58
+ const Term::Terminal* Term::Private::Signals::m_term{nullptr };
59
+
60
+ Term::Private::Signals::Signals (const Terminal& terminal) noexcept
62
61
{
62
+ m_term = &terminal;
63
63
m_handlers.reserve (m_signals_number);
64
64
for (std::size_t signal = 0 ; signal != m_signals_number; ++signal)
65
65
{
Original file line number Diff line number Diff line change @@ -16,21 +16,24 @@ using sighandler_t = void (*)(int);
16
16
namespace Term
17
17
{
18
18
19
+ class Terminal ;
20
+
19
21
namespace Private
20
22
{
21
23
22
24
class Signals
23
25
{
24
26
public:
25
- Signals () noexcept ;
27
+ Signals (const Terminal& ) noexcept ;
26
28
~Signals () noexcept = default ;
27
29
void setHandler (const sighandler_t & handler) noexcept ;
28
- void reset_and_raise (const int & sign) noexcept ;
29
- static void clean_terminal () noexcept ;
30
+ void reset_and_raise (const int & sign) noexcept ;
31
+ static void clean_terminal () noexcept ;
30
32
31
33
private:
32
- const static std::size_t m_signals_number;
33
- std::vector<sighandler_t > m_handlers;
34
+ const static std::size_t m_signals_number;
35
+ std::vector<sighandler_t > m_handlers;
36
+ const static Term::Terminal* m_term;
34
37
};
35
38
36
39
} // namespace Private
Original file line number Diff line number Diff line change 13
13
#include " cpp-terminal/private/file_initializer.hpp"
14
14
#include " cpp-terminal/private/signals.hpp"
15
15
#include " cpp-terminal/terminal.hpp"
16
+ #include " terminal.hpp"
16
17
17
18
#include < new>
18
19
25
26
{
26
27
static const Private::FileInitializer files_init;
27
28
new (&Term::terminal) Terminal ();
28
- static Term::Private::Signals signals;
29
+ static Term::Private::Signals signals (Term::terminal) ;
29
30
sighandler_t handler = [](int signum) { signals.reset_and_raise (signum); };
30
31
signals.setHandler (handler);
31
32
}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ int main()
20
20
{
21
21
Term::terminal.setOptions (Term::Option::Raw, Term::Option::SignalKeys, Term::Option::ClearScreen);
22
22
std::signal (SIGINT,
23
- [](int sig )
23
+ [](int )
24
24
{
25
25
std::ofstream outfile (" cpp_terminal_signal.txt" );
26
26
outfile << " my text here!" << std::endl;
You can’t perform that action at this time.
0 commit comments