diff options
| author | ruki <[email protected]> | 2017-09-25 22:43:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-25 10:21:51 +0800 |
| commit | b2e0a63e0840247d2662f0b7b0ac97b95cebb382 (patch) | |
| tree | 8d9c8e5261464bb96103e6d0592b81132fa3754d | |
| parent | 1cb688b8a4377c521a7dfd23df4de239cc19c817 (diff) | |
enable colors output for windows cmd
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | core/src/xmake/machine.c | 15 | ||||
| -rw-r--r-- | xmake/core/base/colors.lua | 7 |
3 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c530350..29deebbd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Disable to output colors code to file * Update project templates with tbox * Improve `lib.detect.find_program` interface +* Enable colors output for windows cmd ### Bugs fixed @@ -383,6 +384,7 @@ * 禁止在重定向的时候进行彩色输出,避免输出文件中带有色彩代码干扰 * 更新tbox工程模板 * 改进`lib.detect.find_program`模块接口 +* 为windows cmd终端增加彩色输出 ### Bugs修复 diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index ad1c4d366..75fc9548d 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -549,6 +549,21 @@ xm_machine_ref_t xm_machine_init() lua_newtable(impl->lua); lua_setglobal(impl->lua, "xmake"); +#ifdef TB_CONFIG_OS_WINDOWS + // enable terminal colors output for windows cmd + HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); + if (output != INVALID_HANDLE_VALUE) + { + DWORD mode; + if (GetConsoleMode(output, &mode)) + { + // attempt to enable 0x4: ENABLE_VIRTUAL_TERMINAL_PROCESSING + if (SetConsoleMode(output, mode | 0x4)) + tb_environment_set("COLORTERM", "color256"); + } + } +#endif + // ok ok = tb_true; diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index f545dc6ce..d44e4da0d 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -108,6 +108,9 @@ colors._keys24 = colors._escape = string.char(27) .. '[%sm' -- support 256 colors? +-- +-- COLORTERM: color256, truecolor, nocolor +-- function colors.has256() -- get $COLORTERM @@ -118,8 +121,8 @@ function colors.has256() return false end - -- this is supported if be not windows - if os.host() ~= "windows" then + -- has 256 color? + if colors._COLORTERM == "color256" or os.host() ~= "windows" then return true end |
