Add color output to Windows 10 command prompt
This commit is contained in:
@@ -4,6 +4,7 @@ package lime.tools.helpers;
|
|||||||
import haxe.io.Bytes;
|
import haxe.io.Bytes;
|
||||||
import lime.tools.helpers.PlatformHelper;
|
import lime.tools.helpers.PlatformHelper;
|
||||||
import lime.project.Platform;
|
import lime.project.Platform;
|
||||||
|
import lime.system.CFFI;
|
||||||
import sys.io.Process;
|
import sys.io.Process;
|
||||||
|
|
||||||
#if neko
|
#if neko
|
||||||
@@ -121,6 +122,30 @@ class LogHelper {
|
|||||||
|
|
||||||
colorSupported = true;
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
<file name="src/system/Locale.cpp" unless="mac || ios" />
|
<file name="src/system/Locale.cpp" unless="mac || ios" />
|
||||||
<file name="src/system/Locale.mm" if="mac || ios" />
|
<file name="src/system/Locale.mm" if="mac || ios" />
|
||||||
<file name="src/system/SensorEvent.cpp" />
|
<file name="src/system/SensorEvent.cpp" />
|
||||||
<file name="src/system/System.cpp" if="linux" />
|
<file name="src/system/System.cpp" />
|
||||||
<file name="src/system/System.mm" if="ios" />
|
<file name="src/system/System.mm" if="ios" />
|
||||||
<file name="src/ui/DropEvent.cpp" />
|
<file name="src/ui/DropEvent.cpp" />
|
||||||
<file name="src/ui/GamepadEvent.cpp" />
|
<file name="src/ui/GamepadEvent.cpp" />
|
||||||
|
|||||||
@@ -32,12 +32,18 @@ namespace lime {
|
|||||||
static std::wstring* GetIOSDirectory (SystemDirectory type);
|
static std::wstring* GetIOSDirectory (SystemDirectory type);
|
||||||
static bool GetIOSTablet ();
|
static bool GetIOSTablet ();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
static int GetWindowsConsoleMode (int handleType);
|
||||||
|
#endif
|
||||||
static value GetDisplay (int id);
|
static value GetDisplay (int id);
|
||||||
static int GetNumDisplays ();
|
static int GetNumDisplays ();
|
||||||
static double GetTimer ();
|
static double GetTimer ();
|
||||||
static void OpenFile (const char* path);
|
static void OpenFile (const char* path);
|
||||||
static void OpenURL (const char* url, const char* target);
|
static void OpenURL (const char* url, const char* target);
|
||||||
static bool SetAllowScreenTimeout (bool allow);
|
static bool SetAllowScreenTimeout (bool allow);
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
static bool SetWindowsConsoleMode (int handleType, int mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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) {
|
void lime_system_open_file (HxString path) {
|
||||||
|
|
||||||
#ifdef IPHONE
|
#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) {
|
void lime_text_event_manager_register (value callback, value eventObject) {
|
||||||
|
|
||||||
TextEvent::callback = new AutoGCRoot (callback);
|
TextEvent::callback = new AutoGCRoot (callback);
|
||||||
@@ -1896,9 +1918,11 @@ namespace lime {
|
|||||||
DEFINE_PRIME0 (lime_system_get_ios_tablet);
|
DEFINE_PRIME0 (lime_system_get_ios_tablet);
|
||||||
DEFINE_PRIME0 (lime_system_get_num_displays);
|
DEFINE_PRIME0 (lime_system_get_num_displays);
|
||||||
DEFINE_PRIME0 (lime_system_get_timer);
|
DEFINE_PRIME0 (lime_system_get_timer);
|
||||||
|
DEFINE_PRIME1 (lime_system_get_windows_console_mode);
|
||||||
DEFINE_PRIME1v (lime_system_open_file);
|
DEFINE_PRIME1v (lime_system_open_file);
|
||||||
DEFINE_PRIME2v (lime_system_open_url);
|
DEFINE_PRIME2v (lime_system_open_url);
|
||||||
DEFINE_PRIME1 (lime_system_set_allow_screen_timeout);
|
DEFINE_PRIME1 (lime_system_set_allow_screen_timeout);
|
||||||
|
DEFINE_PRIME2 (lime_system_set_windows_console_mode);
|
||||||
DEFINE_PRIME2v (lime_text_event_manager_register);
|
DEFINE_PRIME2v (lime_text_event_manager_register);
|
||||||
DEFINE_PRIME3 (lime_text_layout_create);
|
DEFINE_PRIME3 (lime_text_layout_create);
|
||||||
DEFINE_PRIME5 (lime_text_layout_position);
|
DEFINE_PRIME5 (lime_text_layout_position);
|
||||||
|
|||||||
@@ -1,3 +1,51 @@
|
|||||||
|
#ifdef HX_WINDOWS
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <system/System.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
#ifdef HX_LINUX
|
||||||
|
|
||||||
// Improve compatibility with old glibc
|
// Improve compatibility with old glibc
|
||||||
|
|||||||
Reference in New Issue
Block a user