|
9 | 9 | */ |
10 | 10 |
|
11 | 11 | #include "cpp-terminal/iostream.hpp" |
| 12 | +#include "cpp-terminal/options.hpp" |
12 | 13 | #include "cpp-terminal/terminal.hpp" |
13 | 14 |
|
| 15 | +#include <csignal> |
| 16 | +#include <fstream> |
14 | 17 | #include <iostream> |
15 | 18 |
|
16 | 19 | int main() |
17 | 20 | { |
18 | | - std::at_quick_exit( |
19 | | - []() |
20 | | - { |
21 | | - std::cout << "Unhandled exception\n" << std::flush; |
22 | | - //std::abort(); |
23 | | - }); |
24 | | - std::set_terminate( |
25 | | - []() |
26 | | - { |
27 | | - std::cout << "Unhandled exception\n" << std::flush; |
28 | | - //std::abort(); |
29 | | - }); |
30 | | - Term::terminal.setOptions(Term::Option::Raw, Term::Option::SignalKeys); |
| 21 | + Term::terminal.setOptions(Term::Option::Raw, Term::Option::NoSignalKeys, Term::Option::ClearScreen); |
| 22 | + std::signal(SIGINT, |
| 23 | + [](int sig) |
| 24 | + { |
| 25 | + std::ofstream outfile("cpp_terminal_signal.txt"); |
| 26 | + outfile << "my text here!" << std::endl; |
| 27 | + outfile.close(); |
| 28 | + std::exit(1); |
| 29 | + }); |
| 30 | + std::cout << "This is printed with std::cout with std::end (1)" << std::endl; |
| 31 | + std::clog << "This is printed with std::clog with std::end (2)" << std::endl; |
| 32 | + std::cerr << "This is printed with std::cerr with std::end (3)" << std::endl; |
| 33 | + |
| 34 | + Term::cout << "This is printed with Term::cout with std::end (4)" << std::endl; |
| 35 | + Term::clog << "This is printed with Term::clog with std::end (5)" << std::endl; |
| 36 | + Term::cerr << "This is printed with Term::cerr with std::end (6)" << std::endl; |
| 37 | + |
| 38 | + std::cout << "This is printed with std::cout with flush() (7)\n" << std::flush; |
| 39 | + std::clog << "This is printed with std::clog with flush() (8)\n" << std::flush; |
| 40 | + std::cerr << "This is printed with std::cerr with flush() (9)\n" << std::flush; |
| 41 | + |
| 42 | + Term::cout << "This is printed with Term::cout with flush() (10)\n" << std::flush; |
| 43 | + Term::clog << "This is printed with Term::clog with flush() (11)\n" << std::flush; |
| 44 | + Term::cerr << "This is printed with Term::cerr with flush() (12)\n" << std::flush; |
| 45 | + |
| 46 | + std::cout << "This is printed (13) "; |
| 47 | + std::cout << "with std::cout (13)"; |
| 48 | + std::clog << "This is printed (14) "; |
| 49 | + std::clog << "with std::clog (14)"; |
| 50 | + std::cerr << "This is printed (15) "; |
| 51 | + std::cerr << "with std::cerr (15)"; |
31 | 52 | while(true) {} |
32 | 53 | return 0; |
33 | 54 | } |
0 commit comments