summaryrefslogtreecommitdiff
path: root/xmake/core/base/tty.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-28 00:48:18 +0800
committerruki <[email protected]>2021-01-28 00:48:18 +0800
commitc5615fbc82554d5e85dbc02da493bb59df2cd492 (patch)
tree2287eb98f6c355735c220143ae5657874f6d5db8 /xmake/core/base/tty.lua
parentd98169322f86c2a95d6b4e62a56918414fa1349d (diff)
add tty.has_color256
Diffstat (limited to 'xmake/core/base/tty.lua')
-rw-r--r--xmake/core/base/tty.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/xmake/core/base/tty.lua b/xmake/core/base/tty.lua
index 2698a907e..1ccaedae1 100644
--- a/xmake/core/base/tty.lua
+++ b/xmake/core/base/tty.lua
@@ -263,5 +263,48 @@ function tty.has_color8()
return has_color8
end
+-- has 256 colors?
+function tty.has_color256()
+
+ local has_color256 = tty._HAS_COLOR256
+ if has_color256 == nil then
+
+ -- detect it from $COLORTERM
+ if has_color256 == nil then
+ local colorterm = tty._colorterm()
+ if colorterm == "nocolor" then
+ has_color256 = false
+ elseif colorterm == "color256" or colorterm == "truecolor" then
+ has_color256 = true
+ end
+ end
+
+ -- detect it from $TERM
+ local term = tty.term()
+ local term_env = os.getenv("TERM")
+ if has_color256 == nil then
+ if term == "vstudio" then
+ has_color256 = false
+ elseif term_env and term_env:find("256color", 1, true) then
+ has_color256 = true
+ end
+ end
+
+ -- detect it from system
+ if has_color256 == nil then
+ if os.host() == "windows" then
+ has_color256 = false
+ elseif os.host() == "linux" or os.host("macosx") then
+ -- alway enabled for linux/macOS, $TERM maybe xterm, not xterm-256color, but it is supported
+ has_color256 = true
+ else
+ has_color256 = false
+ end
+ end
+ tty._HAS_COLOR256 = has_color256 or false
+ end
+ return has_color256
+end
+
-- return module
return tty