|
18 | 18 | namespace dart {
|
19 | 19 | namespace bin {
|
20 | 20 |
|
21 |
| -class PosixConsole { |
22 |
| - public: |
23 |
| - static const tcflag_t kInvalidFlag = -1; |
24 |
| - |
25 |
| - static void Initialize() { |
26 |
| - SaveMode(STDOUT_FILENO, &stdout_initial_c_lflag_); |
27 |
| - SaveMode(STDERR_FILENO, &stderr_initial_c_lflag_); |
28 |
| - SaveMode(STDIN_FILENO, &stdin_initial_c_lflag_); |
29 |
| - } |
30 |
| - |
31 |
| - static void Cleanup() { |
32 |
| - RestoreMode(STDOUT_FILENO, stdout_initial_c_lflag_); |
33 |
| - RestoreMode(STDERR_FILENO, stderr_initial_c_lflag_); |
34 |
| - RestoreMode(STDIN_FILENO, stdin_initial_c_lflag_); |
35 |
| - ClearLFlags(); |
36 |
| - } |
37 |
| - |
38 |
| - private: |
39 |
| - static tcflag_t stdout_initial_c_lflag_; |
40 |
| - static tcflag_t stderr_initial_c_lflag_; |
41 |
| - static tcflag_t stdin_initial_c_lflag_; |
42 |
| - |
43 |
| - static void ClearLFlags() { |
44 |
| - stdout_initial_c_lflag_ = kInvalidFlag; |
45 |
| - stderr_initial_c_lflag_ = kInvalidFlag; |
46 |
| - stdin_initial_c_lflag_ = kInvalidFlag; |
47 |
| - } |
48 |
| - |
49 |
| - static void SaveMode(intptr_t fd, tcflag_t* flag) { |
50 |
| - ASSERT(flag != NULL); |
51 |
| - struct termios term; |
52 |
| - int status = TEMP_FAILURE_RETRY(tcgetattr(fd, &term)); |
53 |
| - if (status != 0) { |
54 |
| - return; |
55 |
| - } |
56 |
| - *flag = term.c_lflag; |
57 |
| - } |
58 |
| - |
59 |
| - static void RestoreMode(intptr_t fd, tcflag_t flag) { |
60 |
| - if (flag == kInvalidFlag) { |
61 |
| - return; |
62 |
| - } |
63 |
| - struct termios term; |
64 |
| - int status = TEMP_FAILURE_RETRY(tcgetattr(fd, &term)); |
65 |
| - if (status != 0) { |
66 |
| - return; |
67 |
| - } |
68 |
| - term.c_lflag = flag; |
69 |
| - VOID_TEMP_FAILURE_RETRY(tcsetattr(fd, TCSANOW, &term)); |
70 |
| - } |
71 |
| - |
72 |
| - DISALLOW_ALLOCATION(); |
73 |
| - DISALLOW_IMPLICIT_CONSTRUCTORS(PosixConsole); |
74 |
| -}; |
75 |
| - |
76 |
| -tcflag_t PosixConsole::stdout_initial_c_lflag_ = PosixConsole::kInvalidFlag; |
77 |
| -tcflag_t PosixConsole::stderr_initial_c_lflag_ = PosixConsole::kInvalidFlag; |
78 |
| -tcflag_t PosixConsole::stdin_initial_c_lflag_ = PosixConsole::kInvalidFlag; |
79 |
| - |
80 | 21 | void Console::SaveConfig() {
|
81 |
| - PosixConsole::Initialize(); |
82 | 22 | }
|
83 | 23 |
|
84 | 24 | void Console::RestoreConfig() {
|
85 |
| - PosixConsole::Cleanup(); |
86 | 25 | }
|
87 | 26 |
|
88 | 27 | } // namespace bin
|
|
0 commit comments