summaryrefslogtreecommitdiff
path: root/xmake/core/base
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-02 22:37:00 +0800
committerruki <[email protected]>2019-01-02 09:42:04 +0800
commitcc976c3fc70c83373e2984ee26ccbff4df5efa85 (patch)
tree4bfe845d1040fc15a798bffbb8aebbd241f8550d /xmake/core/base
parent59c8c59a2983c329118f7839b9949635a85183f5 (diff)
add plain theme
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/colors.lua36
-rw-r--r--xmake/core/base/utils.lua4
2 files changed, 36 insertions, 4 deletions
diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua
index 818559480..b0e87bcdc 100644
--- a/xmake/core/base/colors.lua
+++ b/xmake/core/base/colors.lua
@@ -26,7 +26,7 @@
local colors = colors or {}
-- load modules
-local emoji = emoji or require("base/emoji")
+local emoji = require("base/emoji")
-- the color8 keys
--
@@ -298,6 +298,9 @@ function colors.translate(str)
return nil
end
+ -- get theme
+ local theme = colors.theme()
+
-- patch reset
str = "${reset}" .. str .. "${reset}"
@@ -309,7 +312,26 @@ function colors.translate(str)
return ""
end
- -- attempt to translate to emoji first
+ -- translate theme color first, e.g ${color.error}
+ if theme then
+ local theme_word = theme:get(word)
+ if theme_word then
+ word = theme_word
+ end
+ if word == "" then
+ return ""
+ end
+ elseif word:startswith("color.") then
+ local default_colors = {["color.error"] = "bright red", ["color.warning"] = "bright yellow"}
+ local theme_word = default_colors[word]
+ if theme_word then
+ word = theme_word
+ else
+ return ""
+ end
+ end
+
+ -- attempt to translate to emoji
local emoji_str = emoji.translate(word)
if emoji_str then
return emoji_str
@@ -369,5 +391,15 @@ function colors.ignore(str)
return (string.gsub(str, "(%${(.-)})", ""))
end
+-- get theme
+function colors.theme()
+ return colors._THEME
+end
+
+-- set theme
+function colors.theme_set(theme)
+ colors._THEME = theme
+end
+
-- return module
return colors
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index dd54fb9ae..27e59c253 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -150,7 +150,7 @@ end
-- print the error information
function utils.error(format, ...)
if format ~= nil then
- utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
+ utils.cprint("${color.error}error: ${clear}" .. string.tryformat(format, ...))
log:flush()
end
end
@@ -162,7 +162,7 @@ function utils.warning(format, ...)
assert(format)
-- format message
- local msg = "${bright yellow}warning: ${default yellow}" .. string.tryformat(format, ...)
+ local msg = "${color.warning}warning: ${default yellow}" .. string.tryformat(format, ...)
-- init warnings
utils._WARNINGS = utils._WARNINGS or {}