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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/stdio_win.cc
diff --git a/runtime/bin/stdio_win.cc b/runtime/bin/stdio_win.cc
index 8f2a72cf23d0bf89a3d7be248139697249486cd9..40df3a707beb4370409dba5e6298a84a76f8b04f 100644
--- a/runtime/bin/stdio_win.cc
+++ b/runtime/bin/stdio_win.cc
@@ -9,6 +9,16 @@
#include "bin/stdio.h"
+// These are not always defined in the header files. See:
+// https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
+#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
+#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
+#endif
+
+#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+#endif
+
namespace dart {
namespace bin {
@@ -77,6 +87,23 @@ bool Stdin::SetLineMode(bool enabled) {
}
+bool Stdin::AnsiSupported(bool* supported) {
+ ASSERT(supported != NULL);
+ HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
+ if (h == INVALID_HANDLE_VALUE) {
+ *supported = false;
+ return false;
+ }
+ DWORD mode;
+ if (!GetConsoleMode(h, &mode)) {
+ *supported = false;
+ return false;
+ }
+ *supported = (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) != 0;
+ return true;
+}
+
+
bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
HANDLE h;
if (fd == 1) {
@@ -93,6 +120,28 @@ bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
return true;
}
+
+bool Stdout::AnsiSupported(intptr_t fd, bool* supported) {
+ ASSERT(supported != NULL);
+ HANDLE h;
+ if (fd == 1) {
+ h = GetStdHandle(STD_OUTPUT_HANDLE);
+ } else {
+ h = GetStdHandle(STD_ERROR_HANDLE);
+ }
+ if (h == INVALID_HANDLE_VALUE) {
+ *supported = false;
+ return false;
+ }
+ DWORD mode;
+ if (!GetConsoleMode(h, &mode)) {
+ *supported = false;
+ return false;
+ }
+ *supported = (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0;
+ return true;
+}
+
} // namespace bin
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698