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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(HOST_OS_WINDOWS) | 8 #if defined(HOST_OS_WINDOWS) |
9 | 9 |
10 #include "bin/stdio.h" | 10 #include "bin/stdio.h" |
11 | 11 |
| 12 // These are not always defined in the header files. See: |
| 13 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).as
px |
| 14 #ifndef ENABLE_VIRTUAL_TERMINAL_INPUT |
| 15 #define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200 |
| 16 #endif |
| 17 |
| 18 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING |
| 19 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 |
| 20 #endif |
| 21 |
12 namespace dart { | 22 namespace dart { |
13 namespace bin { | 23 namespace bin { |
14 | 24 |
15 bool Stdin::ReadByte(int* byte) { | 25 bool Stdin::ReadByte(int* byte) { |
16 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); | 26 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
17 uint8_t buffer[1]; | 27 uint8_t buffer[1]; |
18 DWORD read = 0; | 28 DWORD read = 0; |
19 BOOL success = ReadFile(h, buffer, 1, &read, NULL); | 29 BOOL success = ReadFile(h, buffer, 1, &read, NULL); |
20 if (!success && (GetLastError() != ERROR_BROKEN_PIPE)) { | 30 if (!success && (GetLastError() != ERROR_BROKEN_PIPE)) { |
21 return false; | 31 return false; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 80 } |
71 if (enabled) { | 81 if (enabled) { |
72 mode |= ENABLE_LINE_INPUT; | 82 mode |= ENABLE_LINE_INPUT; |
73 } else { | 83 } else { |
74 mode &= ~ENABLE_LINE_INPUT; | 84 mode &= ~ENABLE_LINE_INPUT; |
75 } | 85 } |
76 return SetConsoleMode(h, mode); | 86 return SetConsoleMode(h, mode); |
77 } | 87 } |
78 | 88 |
79 | 89 |
| 90 bool Stdin::AnsiSupported(bool* supported) { |
| 91 HANDLE h = GetStdHandle(STD_INPUT_HANDLE); |
| 92 if (h == INVALID_HANDLE_VALUE) { |
| 93 return false; |
| 94 } |
| 95 DWORD mode; |
| 96 if (!GetConsoleMode(h, &mode)) { |
| 97 return false; |
| 98 } |
| 99 *supported = (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) != 0; |
| 100 return true; |
| 101 } |
| 102 |
| 103 |
80 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { | 104 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { |
81 HANDLE h; | 105 HANDLE h; |
82 if (fd == 1) { | 106 if (fd == 1) { |
83 h = GetStdHandle(STD_OUTPUT_HANDLE); | 107 h = GetStdHandle(STD_OUTPUT_HANDLE); |
84 } else { | 108 } else { |
85 h = GetStdHandle(STD_ERROR_HANDLE); | 109 h = GetStdHandle(STD_ERROR_HANDLE); |
86 } | 110 } |
87 CONSOLE_SCREEN_BUFFER_INFO info; | 111 CONSOLE_SCREEN_BUFFER_INFO info; |
88 if (!GetConsoleScreenBufferInfo(h, &info)) { | 112 if (!GetConsoleScreenBufferInfo(h, &info)) { |
89 return false; | 113 return false; |
90 } | 114 } |
91 size[0] = info.srWindow.Right - info.srWindow.Left + 1; | 115 size[0] = info.srWindow.Right - info.srWindow.Left + 1; |
92 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1; | 116 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1; |
93 return true; | 117 return true; |
94 } | 118 } |
95 | 119 |
| 120 |
| 121 bool Stdout::AnsiSupported(intptr_t fd, bool* supported) { |
| 122 HANDLE h; |
| 123 if (fd == 1) { |
| 124 h = GetStdHandle(STD_OUTPUT_HANDLE); |
| 125 } else { |
| 126 h = GetStdHandle(STD_ERROR_HANDLE); |
| 127 } |
| 128 if (h == INVALID_HANDLE_VALUE) { |
| 129 return false; |
| 130 } |
| 131 DWORD mode; |
| 132 if (!GetConsoleMode(h, &mode)) { |
| 133 return false; |
| 134 } |
| 135 *supported = (mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0; |
| 136 return true; |
| 137 } |
| 138 |
96 } // namespace bin | 139 } // namespace bin |
97 } // namespace dart | 140 } // namespace dart |
98 | 141 |
99 #endif // defined(HOST_OS_WINDOWS) | 142 #endif // defined(HOST_OS_WINDOWS) |
100 | 143 |
101 #endif // !defined(DART_IO_DISABLED) | 144 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |