summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-26 21:02:14 +0800
committerruki <[email protected]>2021-01-26 21:02:14 +0800
commit9a816217dc6263c756a28863a38be7e27a5404fa (patch)
tree6fe1e14c8262c4b3509d8f0cbcc031d8252da1d4
parentf6382212c2453aa122aa2c0d7eace55f382f7836 (diff)
improve has_emoji
-rw-r--r--xmake/core/base/colors.lua14
1 files changed, 3 insertions, 11 deletions
diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua
index 36846bab2..f327db10d 100644
--- a/xmake/core/base/colors.lua
+++ b/xmake/core/base/colors.lua
@@ -22,6 +22,7 @@
local colors = colors or {}
-- load modules
+local tty -- lazy loading it
local emoji = require("base/emoji")
-- the color8 keys
@@ -208,16 +209,6 @@ function colors.truecolor()
return colorterm:find("truecolor", 1, true) or colorterm:find("24bit", 1, true)
end
--- support emoji?
-function colors.emoji()
- local emoji = colors._EMOJI
- if emoji == nil then
- emoji = not os.getenv("XMAKE_COLORTERM_NOEMOJI")
- colors._EMOJI = emoji
- end
- return emoji
-end
-
-- make rainbow truecolor code by the index of characters
--
-- @param index the index of characters
@@ -327,6 +318,7 @@ function colors.translate(str, opt)
end
-- translate color blocks, e.g. ${red}, ${color.xxx}, ${emoji}
+ tty = tty or require("base/tty")
str = str:gsub("(%${(.-)})", function(_, word)
-- not supported? ignore it
@@ -336,7 +328,7 @@ function colors.translate(str, opt)
end
-- is plain theme? no colors and no emoji
- local noemoji = not colors.emoji()
+ local noemoji = not tty.has_emoji()
if opt.plain or (theme and theme:name() == "plain") then
nocolors = true
noemoji = true