diff options
| author | ruki <[email protected]> | 2017-08-18 11:44:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-18 11:46:56 +0800 |
| commit | b714bf39904f7425a32d5238d0737239a6e5d045 (patch) | |
| tree | 4d74ce8d2508356d823df4de71b93092744025fa | |
| parent | 7c11f1e69f0aa3bf30410f660dff16a647860320 (diff) | |
detect true color
| -rw-r--r-- | docs/manual.md | 9 | ||||
| -rw-r--r-- | docs/zh/manual.md | 9 | ||||
| -rw-r--r-- | xmake/core/base/colors.lua | 28 |
3 files changed, 40 insertions, 6 deletions
diff --git a/docs/manual.md b/docs/manual.md index b794a88b5..5eb1a20df 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -3990,6 +3990,15 @@ if colors.truecolor() then end ``` +xmake对于truecolor的检测支持,是通过`$COLORTERM`环境变量来实现的,如果你的终端支持truecolor,可以手动设置此环境变量,来告诉xmake启用truecolor支持。 + +可以通过下面的命令来启用和测试: + +```bash +$ export COLORTERM=truecolor +$ xmake --version +``` + ##### cprintf ###### 无换行彩色打印终端日志 diff --git a/docs/zh/manual.md b/docs/zh/manual.md index f20a94079..0008c546e 100644 --- a/docs/zh/manual.md +++ b/docs/zh/manual.md @@ -4007,6 +4007,15 @@ if colors.truecolor() then end ``` +xmake对于truecolor的检测支持,是通过`$COLORTERM`环境变量来实现的,如果你的终端支持truecolor,可以手动设置此环境变量,来告诉xmake启用truecolor支持。 + +可以通过下面的命令来启用和测试: + +```bash +$ export COLORTERM=truecolor +$ xmake --version +``` + ##### cprintf ###### 无换行彩色打印终端日志 diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index d0fedcd81..9fe7790ae 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -116,16 +116,32 @@ function colors.has256() end -- this is supported if exists ANSICON envirnoment variable on windows - return os.getenv("ANSICON") + colors._ANSICON = colors._ANSICON or os.getenv("ANSICON") + return colors._ANSICON end --- support 24bits true colors +-- support 24bits true color +-- +-- There's no reliable way, and ncurses/terminfo's maintainer expressed he has no intent on introducing support. +-- S-Lang author added a check for $COLORTERM containing either "truecolor" or "24bit" (case sensitive). +-- In turn, VTE, Konsole and iTerm2 set this variable to "truecolor" (it's been there in VTE for a while, +-- it's relatively new and maybe still git-only in Konsole and iTerm2). +-- +-- This is obviously not a reliable method, and is not forwarded via sudo, ssh etc. However, whenever it errs, +-- it errs on the safe side: does not advertise support whereas it's actually supported. +-- App developers can freely choose to check for this same variable, or introduce their own method +-- (e.g. an option in their config file), whichever matches better the overall design of the given app. +-- Checking $COLORTERM is recommended though, since that would lead to a more unique desktop experience +-- where the user has to set one variable only and it takes effect across all the apps, rather than something +-- separately for each app. +-- function colors.truecolor() - -- this is supported if be not windows - if os.host() ~= "windows" then --- return true - end + -- get $COLORTERM + colors._COLORTERM = colors._COLORTERM or os.getenv("COLORTERM") or "" + + -- support true color? + return colors._COLORTERM:find("truecolor", 1, true) or colors._COLORTERM:find("24bit", 1, true) end -- make rainbow color code by the index of characters |
