17
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
*/
19
19
#include < bitcoin/system/unicode/utf8_everywhere/stdio.hpp>
20
-
20
+ # include < windows.h >
21
21
#ifdef HAVE_MSC
22
22
#include < fcntl.h>
23
23
#include < io.h>
24
24
#include < windows.h>
25
25
#else
26
- #include < termios.h>
26
+ #if !defined(_WIN32)
27
+ #include < termios.h>
28
+ #endif
27
29
#endif
28
30
#include < mutex>
29
31
#include < bitcoin/system/define.hpp>
@@ -80,21 +82,28 @@ inline void set_binary_stdio(FILE* file) THROWS
80
82
throw runtime_exception{ " Could not set STDIO to binary mode." };
81
83
}
82
84
83
- void set_console_echo () NOEXCEPT
84
- {
85
- const auto handle = GetStdHandle (STD_INPUT_HANDLE) ;
86
- DWORD mode{} ;
87
- GetConsoleMode (handle, &mode) ;
88
- SetConsoleMode (handle, mode | ENABLE_ECHO_INPUT );
85
+ # ifndef _WIN32
86
+ void set_console_echo () {
87
+ termios terminal{} ;
88
+ tcgetattr ( 0 , &terminal) ;
89
+ terminal. c_lflag |= ECHO ;
90
+ tcsetattr (STDIN_FILENO, TCSAFLUSH, &terminal );
89
91
}
90
92
91
- void unset_console_echo () NOEXCEPT
92
- {
93
- const auto handle = GetStdHandle (STD_INPUT_HANDLE);
94
- DWORD mode{};
95
- GetConsoleMode (handle, &mode);
96
- SetConsoleMode (handle, mode & ~ENABLE_ECHO_INPUT);
93
+ void unset_console_echo () {
94
+ termios terminal{};
95
+ tcgetattr (0 , &terminal);
96
+ terminal.c_lflag &= ~ECHO;
97
+ tcsetattr (STDIN_FILENO, TCSAFLUSH, &terminal);
98
+ }
99
+ #else
100
+ void set_console_echo () {
101
+ // TODO: Windows console echo handling if needed
97
102
}
103
+ void unset_console_echo () {
104
+ // TODO: Windows console echo handling if needed
105
+ }
106
+ #endif
98
107
99
108
#else // HAVE_MSC
100
109
@@ -104,21 +113,28 @@ std::ostream& cerr_stream() THROWS { return std::cerr; }
104
113
inline void set_utf8_stdio (FILE*) THROWS {}
105
114
inline void set_binary_stdio (FILE*) THROWS {}
106
115
107
- void set_console_echo () NOEXCEPT
108
- {
116
+ # ifndef _WIN32
117
+ void set_console_echo () {
109
118
termios terminal{};
110
119
tcgetattr (0 , &terminal);
111
120
terminal.c_lflag |= ECHO;
112
121
tcsetattr (STDIN_FILENO, TCSAFLUSH, &terminal);
113
122
}
114
123
115
- void unset_console_echo () NOEXCEPT
116
- {
124
+ void unset_console_echo () {
117
125
termios terminal{};
118
126
tcgetattr (0 , &terminal);
119
127
terminal.c_lflag &= ~ECHO;
120
128
tcsetattr (STDIN_FILENO, TCSAFLUSH, &terminal);
121
129
}
130
+ #else
131
+ void set_console_echo () {
132
+ // TODO: Windows console echo handling if needed
133
+ }
134
+ void unset_console_echo () {
135
+ // TODO: Windows console echo handling if needed
136
+ }
137
+ #endif
122
138
123
139
#endif // HAVE_MSC
124
140
0 commit comments