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 /xmake | |
| parent | 7c11f1e69f0aa3bf30410f660dff16a647860320 (diff) | |
detect true color
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/colors.lua | 28 |
1 files changed, 22 insertions, 6 deletions
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 |
