OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/stdin.h" | 8 #include "bin/stdin.h" |
9 | 9 |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 namespace bin { | 12 namespace bin { |
13 | 13 |
14 int Stdin::ReadByte() { | 14 int Stdin::ReadByte() { |
15 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | 15 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
16 uint8_t buffer[1]; | 16 uint8_t buffer[1]; |
17 DWORD read = 0; | 17 DWORD read = 0; |
18 int c = -1; | 18 int c = -1; |
19 if (ReadFile(h, buffer, 1, &read, NULL) && read == 1) { | 19 if (ReadFile(h, buffer, 1, &read, NULL) && read == 1) { |
20 c = buffer[0]; | 20 c = buffer[0]; |
21 } | 21 } |
22 return c; | 22 return c; |
23 } | 23 } |
24 | 24 |
25 | 25 |
| 26 bool Stdin::GetEchoMode() { |
| 27 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
| 28 DWORD mode; |
| 29 if (!GetConsoleMode(h, &mode)) return false; |
| 30 return (mode & ENABLE_ECHO_INPUT) != 0; |
| 31 } |
| 32 |
| 33 |
26 void Stdin::SetEchoMode(bool enabled) { | 34 void Stdin::SetEchoMode(bool enabled) { |
27 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | 35 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
28 DWORD mode; | 36 DWORD mode; |
29 if (!GetConsoleMode(h, &mode)) return; | 37 if (!GetConsoleMode(h, &mode)) return; |
30 if (enabled) { | 38 if (enabled) { |
31 mode |= ENABLE_ECHO_INPUT; | 39 mode |= ENABLE_ECHO_INPUT; |
32 } else { | 40 } else { |
33 mode &= ~ENABLE_ECHO_INPUT; | 41 mode &= ~ENABLE_ECHO_INPUT; |
34 } | 42 } |
35 SetConsoleMode(h, mode); | 43 SetConsoleMode(h, mode); |
36 } | 44 } |
37 | 45 |
38 | 46 |
| 47 bool Stdin::GetLineMode() { |
| 48 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
| 49 DWORD mode; |
| 50 if (!GetConsoleMode(h, &mode)) return false; |
| 51 return (mode & ENABLE_LINE_INPUT) != 0; |
| 52 } |
| 53 |
| 54 |
39 void Stdin::SetLineMode(bool enabled) { | 55 void Stdin::SetLineMode(bool enabled) { |
40 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | 56 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
41 DWORD mode; | 57 DWORD mode; |
42 if (!GetConsoleMode(h, &mode)) return; | 58 if (!GetConsoleMode(h, &mode)) return; |
43 if (enabled) { | 59 if (enabled) { |
44 mode |= ENABLE_LINE_INPUT; | 60 mode |= ENABLE_LINE_INPUT; |
45 } else { | 61 } else { |
46 mode &= ~ENABLE_LINE_INPUT; | 62 mode &= ~ENABLE_LINE_INPUT; |
47 } | 63 } |
48 SetConsoleMode(h, mode); | 64 SetConsoleMode(h, mode); |
49 } | 65 } |
50 | 66 |
51 } // namespace bin | 67 } // namespace bin |
52 } // namespace dart | 68 } // namespace dart |
53 | 69 |
54 #endif // defined(TARGET_OS_WINDOWS) | 70 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |