Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: runtime/bin/stdio_win.cc

Issue 2753233002: [dart:io] Move Platform.ansiSupported to {Stdin,Stdout}.supportsAnsiEscapes (Closed)
Patch Set: Fix typo Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ASSERT(supported != NULL);
92 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
93 if (h == INVALID_HANDLE_VALUE) {
94 *supported = false;
95 return false;
96 }
97 DWORD mode;
98 if (!GetConsoleMode(h, &mode)) {
99 *supported = false;
100 return false;
101 }
102 *supported = (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) != 0;
103 return true;
104 }
105
106
80 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) { 107 bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
81 HANDLE h; 108 HANDLE h;
82 if (fd == 1) { 109 if (fd == 1) {
83 h = GetStdHandle(STD_OUTPUT_HANDLE); 110 h = GetStdHandle(STD_OUTPUT_HANDLE);
84 } else { 111 } else {
85 h = GetStdHandle(STD_ERROR_HANDLE); 112 h = GetStdHandle(STD_ERROR_HANDLE);
86 } 113 }
87 CONSOLE_SCREEN_BUFFER_INFO info; 114 CONSOLE_SCREEN_BUFFER_INFO info;
88 if (!GetConsoleScreenBufferInfo(h, &info)) { 115 if (!GetConsoleScreenBufferInfo(h, &info)) {
89 return false; 116 return false;
90 } 117 }
91 size[0] = info.srWindow.Right - info.srWindow.Left + 1; 118 size[0] = info.srWindow.Right - info.srWindow.Left + 1;
92 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1; 119 size[1] = info.srWindow.Bottom - info.srWindow.Top + 1;
93 return true; 120 return true;
94 } 121 }
95 122
123
124 bool Stdout::AnsiSupported(intptr_t fd, bool* supported) {
125 ASSERT(supported != NULL);
126 HANDLE h;
127 if (fd == 1) {
128 h = GetStdHandle(STD_OUTPUT_HANDLE);
129 } else {
130 h = GetStdHandle(STD_ERROR_HANDLE);
131 }
132 if (h == INVALID_HANDLE_VALUE) {
133 *supported = false;
134 return false;
135 }
136 DWORD mode;
137 if (!GetConsoleMode(h, &mode)) {
138 *supported = false;
139 return false;
140 }
141 *supported = (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0;
142 return true;
143 }
144
96 } // namespace bin 145 } // namespace bin
97 } // namespace dart 146 } // namespace dart
98 147
99 #endif // defined(HOST_OS_WINDOWS) 148 #endif // defined(HOST_OS_WINDOWS)
100 149
101 #endif // !defined(DART_IO_DISABLED) 150 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698