diff --git a/lime/tools/helpers/LogHelper.hx b/lime/tools/helpers/LogHelper.hx
index dac84ff9e..1e2523d06 100644
--- a/lime/tools/helpers/LogHelper.hx
+++ b/lime/tools/helpers/LogHelper.hx
@@ -4,6 +4,7 @@ package lime.tools.helpers;
import haxe.io.Bytes;
import lime.tools.helpers.PlatformHelper;
import lime.project.Platform;
+import lime.system.CFFI;
import sys.io.Process;
#if neko
@@ -121,6 +122,30 @@ class LogHelper {
colorSupported = true;
+ } else if (CFFI.enabled) {
+
+ var getConsoleMode = CFFI.load ("lime", "lime_system_get_windows_console_mode", 1);
+ var setConsoleMode = CFFI.load ("lime", "lime_system_set_windows_console_mode", 2);
+
+ var STD_INPUT_HANDLE = -10;
+ var STD_OUTPUT_HANDLE = -11;
+ var STD_ERROR_HANDLE = -12;
+
+ var ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
+ var ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
+ var DISABLE_NEWLINE_AUTO_RETURN = 0x0008;
+
+ var outputMode = getConsoleMode (STD_OUTPUT_HANDLE);
+ outputMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
+
+ var errorMode = getConsoleMode (STD_ERROR_HANDLE);
+ errorMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
+
+ var success = setConsoleMode (STD_OUTPUT_HANDLE, outputMode);
+ success = success && setConsoleMode (STD_ERROR_HANDLE, errorMode);
+
+ colorSupported = success;
+
}
}
diff --git a/project/Build.xml b/project/Build.xml
index ff7f71bcb..8077ef46d 100644
--- a/project/Build.xml
+++ b/project/Build.xml
@@ -261,7 +261,7 @@
-
+
diff --git a/project/include/system/System.h b/project/include/system/System.h
index 393e7b5d4..ff0f9693f 100644
--- a/project/include/system/System.h
+++ b/project/include/system/System.h
@@ -32,12 +32,18 @@ namespace lime {
static std::wstring* GetIOSDirectory (SystemDirectory type);
static bool GetIOSTablet ();
#endif
+ #ifdef HX_WINDOWS
+ static int GetWindowsConsoleMode (int handleType);
+ #endif
static value GetDisplay (int id);
static int GetNumDisplays ();
static double GetTimer ();
static void OpenFile (const char* path);
static void OpenURL (const char* url, const char* target);
static bool SetAllowScreenTimeout (bool allow);
+ #ifdef HX_WINDOWS
+ static bool SetWindowsConsoleMode (int handleType, int mode);
+ #endif
};
diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp
index 5627543bd..84c23f7f7 100644
--- a/project/src/ExternalInterface.cpp
+++ b/project/src/ExternalInterface.cpp
@@ -1439,6 +1439,17 @@ namespace lime {
}
+ int lime_system_get_windows_console_mode (int handleType) {
+
+ #ifdef HX_WINDOWS
+ return System::GetWindowsConsoleMode (handleType);
+ #else
+ return 0;
+ #endif
+
+ }
+
+
void lime_system_open_file (HxString path) {
#ifdef IPHONE
@@ -1464,6 +1475,17 @@ namespace lime {
}
+ bool lime_system_set_windows_console_mode (int handleType, int mode) {
+
+ #ifdef HX_WINDOWS
+ return System::SetWindowsConsoleMode (handleType, mode);
+ #else
+ return false;
+ #endif
+
+ }
+
+
void lime_text_event_manager_register (value callback, value eventObject) {
TextEvent::callback = new AutoGCRoot (callback);
@@ -1896,9 +1918,11 @@ namespace lime {
DEFINE_PRIME0 (lime_system_get_ios_tablet);
DEFINE_PRIME0 (lime_system_get_num_displays);
DEFINE_PRIME0 (lime_system_get_timer);
+ DEFINE_PRIME1 (lime_system_get_windows_console_mode);
DEFINE_PRIME1v (lime_system_open_file);
DEFINE_PRIME2v (lime_system_open_url);
DEFINE_PRIME1 (lime_system_set_allow_screen_timeout);
+ DEFINE_PRIME2 (lime_system_set_windows_console_mode);
DEFINE_PRIME2v (lime_text_event_manager_register);
DEFINE_PRIME3 (lime_text_layout_create);
DEFINE_PRIME5 (lime_text_layout_position);
diff --git a/project/src/system/System.cpp b/project/src/system/System.cpp
index 9a1c5e4e7..ea8e5df5b 100644
--- a/project/src/system/System.cpp
+++ b/project/src/system/System.cpp
@@ -1,3 +1,51 @@
+#ifdef HX_WINDOWS
+#include
+#endif
+
+#include
+
+
+namespace lime {
+
+
+ #ifdef HX_WINDOWS
+ int System::GetWindowsConsoleMode (int handleType) {
+
+ HANDLE handle = GetStdHandle ((DWORD)handleType);
+ DWORD mode = 0;
+
+ if (handle) {
+
+ bool result = GetConsoleMode (handle, &mode);
+
+ }
+
+ return mode;
+
+ }
+ #endif
+
+
+ #ifdef HX_WINDOWS
+ bool System::SetWindowsConsoleMode (int handleType, int mode) {
+
+ HANDLE handle = GetStdHandle ((DWORD)handleType);
+
+ if (handle) {
+
+ return SetConsoleMode (handle, (DWORD)mode);
+
+ }
+
+ return false;
+
+ }
+ #endif
+
+
+}
+
+
#ifdef HX_LINUX
// Improve compatibility with old glibc