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

Unified Diff: runtime/bin/platform_win.cc

Issue 2734323002: [dart:io][windows] Set Console VT modes (Closed)
Patch Set: Add a comment with a doc link 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index 640f99b1b11c840c4ab1186fb917b213ae556222..85ce6b59094d28caaadb39128a743ad197df2a19 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -19,6 +19,12 @@
#include "bin/utils.h"
#include "bin/utils_win.h"
+// This is 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 0x200
+#endif
+
namespace dart {
// Defined in vm/os_thread_win.cc
@@ -49,24 +55,52 @@ class PlatformWin {
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
}
- static void SaveAndSetOutputCP() {
+ static void SaveAndConfigureConsole() {
MutexLocker ml(platform_win_mutex_);
ASSERT(saved_output_cp_ == -1);
saved_output_cp_ = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);
+
+ HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
+ if ((out != INVALID_HANDLE_VALUE) &&
+ GetConsoleMode(out, &saved_console_out_mode_)) {
+ const DWORD request =
+ saved_console_out_mode_ | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+ SetConsoleMode(out, request);
+ }
+
+ HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
+ if ((in != INVALID_HANDLE_VALUE) &&
+ GetConsoleMode(in, &saved_console_in_mode_)) {
+ const DWORD request =
+ saved_console_in_mode_ | ENABLE_VIRTUAL_TERMINAL_INPUT;
+ SetConsoleMode(in, request);
+ }
}
- static void RestoreOutputCP() {
+ static void RestoreConsole() {
MutexLocker ml(platform_win_mutex_);
if (saved_output_cp_ != -1) {
SetConsoleOutputCP(saved_output_cp_);
saved_output_cp_ = -1;
}
+ HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (out != INVALID_HANDLE_VALUE) {
+ SetConsoleMode(out, saved_console_out_mode_);
+ saved_console_out_mode_ = 0;
+ }
+ HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
+ if (in != INVALID_HANDLE_VALUE) {
+ SetConsoleMode(in, saved_console_in_mode_);
+ saved_console_in_mode_ = 0;
+ }
}
private:
static Mutex* platform_win_mutex_;
static int saved_output_cp_;
+ static DWORD saved_console_out_mode_;
+ static DWORD saved_console_in_mode_;
static void InvalidParameterHandler(const wchar_t* expression,
const wchar_t* function,
@@ -82,11 +116,13 @@ class PlatformWin {
};
int PlatformWin::saved_output_cp_ = -1;
+DWORD PlatformWin::saved_console_out_mode_ = 0;
+DWORD PlatformWin::saved_console_in_mode_ = 0;
Mutex* PlatformWin::platform_win_mutex_ = NULL;
bool Platform::Initialize() {
PlatformWin::InitOnce();
- PlatformWin::SaveAndSetOutputCP();
+ PlatformWin::SaveAndConfigureConsole();
return true;
}
@@ -183,7 +219,7 @@ void Platform::Exit(int exit_code) {
// TODO(zra): Remove once VM shuts down cleanly.
::dart::private_flag_windows_run_tls_destructors = false;
// Restore the console's output code page
- PlatformWin::RestoreOutputCP();
+ PlatformWin::RestoreConsole();
// On Windows we use ExitProcess so that threads can't clobber the exit_code.
// See: https://code.google.com/p/nativeclient/issues/detail?id=2870
::ExitProcess(exit_code);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698