Merge pull request #2512 from spnethw/tmppanel_fix_menu_from_file_list_crash
[far2l.git] / utils / src / TTYRawMode.cpp
blobeda4866f5e12f022545a9b6483d5ea20569d941d
1 #include <stdio.h>
2 #include "TTYRawMode.h"
4 TTYRawMode::TTYRawMode(int std_in, int std_out)
6 // try first stdout, but if it fails - try stdin
7 // this helps to work with specific cases of redirected
8 // output, like working with tee
9 if (tcgetattr(std_out, &_ts) != 0) {
10 if (tcgetattr(std_in, &_ts) != 0) {
11 return;
13 _fd = std_in;
14 } else {
15 _fd = std_out;
18 struct termios ts_ne = _ts;
19 cfmakeraw(&ts_ne);
20 if (tcsetattr( _fd, TCSADRAIN, &ts_ne ) != 0) {
21 _fd = -1;
25 TTYRawMode::~TTYRawMode()
27 if (_fd != -1) {
28 if (tcsetattr(_fd, TCSADRAIN, &_ts) != 0) {
29 perror("~TTYRawMode - tcsetattr");