diff options
| author | ruki <[email protected]> | 2019-01-03 22:53:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-03 11:20:01 +0800 |
| commit | 2bf304a53d08b0d2f248732b4687ae8276aa5e5f (patch) | |
| tree | 2fab13d3167db2ac54e8467b613b093c3663e8a1 | |
| parent | 5e96c7f81c2d20ca081b4c7a854c424b0ff8f56d (diff) | |
improve colors
| -rw-r--r-- | xmake/actions/require/impl/action/download.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/require/impl/action/install.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/colors.lua | 84 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 6 | ||||
| -rw-r--r-- | xmake/themes/emoji/xmake.lua | 24 |
5 files changed, 69 insertions, 57 deletions
diff --git a/xmake/actions/require/impl/action/download.lua b/xmake/actions/require/impl/action/download.lua index 813121dd5..7e7818a8c 100644 --- a/xmake/actions/require/impl/action/download.lua +++ b/xmake/actions/require/impl/action/download.lua @@ -82,7 +82,7 @@ function _checkout(package, url, sourcedir, url_alias) -- trace printf("\r" .. _emptychars()) - cprint("\r${yellow} => ${clear}clone %s %s .. ${green}ok", url, package:version_str()) + cprint("\r${yellow} => ${clear}clone %s %s .. ${color.success}${text.success}", url, package:version_str()) end -- download codes from ftp/http/https @@ -132,7 +132,7 @@ function _download(package, url, sourcedir, url_alias, url_excludes) -- trace if not cached then printf("\r" .. _emptychars()) - cprint("\r${yellow} => ${clear}download %s .. ${green}ok", url) + cprint("\r${yellow} => ${clear}download %s .. ${color.success}${text.success}", url) else printf("\r" .. _emptychars() .. "\r") end @@ -213,9 +213,9 @@ function main(package) -- trace printf("\r" .. _emptychars()) if git.checkurl(url) then - cprint("\r${yellow} => ${clear}clone %s %s .. ${red}failed", url, package:version_str()) + cprint("\r${yellow} => ${clear}clone %s %s .. ${color.failure}${text.failure}", url, package:version_str()) else - cprint("\r${yellow} => ${clear}download %s .. ${red}failed", url) + cprint("\r${yellow} => ${clear}download %s .. ${color.failure}${text.failure}", url) end -- failed? break it diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua index fc1f4d6af..eb1c6c9eb 100644 --- a/xmake/actions/require/impl/action/install.lua +++ b/xmake/actions/require/impl/action/install.lua @@ -123,7 +123,7 @@ function main(package) assert(fetchinfo, "fetch %s failed!", tipname) -- trace - cprint("${green}ok") + cprint("${color.success}${text.success}") end, catch @@ -136,7 +136,7 @@ function main(package) end -- trace - cprint("${color.error.bright}failed") + cprint("${color.failure}${text.failure}") -- failed if not package:requireinfo().optional then diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index b78a26b12..112352116 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -312,73 +312,85 @@ function colors.translate(str) return "" end - -- translate theme color first, e.g ${color.error.bright} - if theme then - local theme_word = theme:get(word) - if theme_word then - if word:startswith("text.") then - return theme_word - else - word = theme_word - end - end - if word == "" then - return "" - end - elseif word:startswith("color.") then - local default_colors = {["color.error.bright"] = "bright red", ["color.warning.bright"] = "bright yellow"} - local theme_word = default_colors[word] - if theme_word then - word = theme_word - else - return "" - end - end - -- get keys local keys = colors.color256() and colors._keys256 or colors._keys8 if colors.truecolor() then keys = colors._keys24 end + -- split words + local blocks_raw = word:split("%s+") + + -- translate theme color first, e.g ${color.error} + local blocks = {} + for _, block in ipairs(blocks_raw) do + if theme then + local theme_block = theme:get(block) + if theme_block then + if block:startswith("text.") then + table.insert(blocks, theme_block) + else + for _, theme_block_sub in ipairs(theme_block:split("%s+")) do + table.insert(blocks, theme_block_sub) + end + end + else + table.insert(blocks, block) + end + elseif block:startswith("color.") then + local default_colors = {["color.error.bright"] = {"bright", "red"}, ["color.warning.bright"] = {"bright", "yellow"}} + local theme_block = default_colors[block] + if theme_block then + table.join2(blocks, theme_block) + else + table.insert(blocks, block) + end + else + table.insert(blocks, block) + end + end + -- make color buffer local text_buffer = {} local color_buffer = {} - for _, key in ipairs(word:split("%s+")) do + for _, block in ipairs(blocks) do -- get the color code - local code = keys[key] local text = false + local code = keys[block] if not code then - if colors.truecolor() and key:find(";", 1, true) then - if key:startswith("on;") then - code = key:gsub("on;", "48;2;") + if colors.truecolor() and block:find(";", 1, true) then + if block:startswith("on;") then + code = block:gsub("on;", "48;2;") else - code = "38;2;" .. key + code = "38;2;" .. block end - elseif colors.color256() and key:find("#", 1, true) then - if key:startswith("on#") then - code = key:gsub("on#", "48;5;") + elseif colors.color256() and block:find("#", 1, true) then + if block:startswith("on#") then + code = block:gsub("on#", "48;5;") else - code = key:gsub("#", "38;5;") + code = block:gsub("#", "38;5;") end else -- get emoji code - local emoji_code = emoji.translate(key) + local emoji_code = emoji.translate(block) if emoji_code then table.insert(text_buffer, emoji_code) text = true end end end - assert(code or text, "unknown color: " .. key) + assert(code or text, "unknown color: " .. block) -- save this code table.insert(color_buffer, code) end -- make result - local result = colors._escape:format(table.concat(color_buffer, ";")) + local result = "" + if #color_buffer > 0 then + result = result .. colors._escape:format(table.concat(color_buffer, ";")) + end if #text_buffer > 0 then result = result .. table.concat(text_buffer, "") end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index a047f09a7..84e5df01d 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -72,7 +72,7 @@ function sandbox_lib_detect_find_program._check(program, opt) -- check failed? print verbose error info if not ok and option.get("diagnosis") then - utils.cprint("${yellow}checkinfo: ${clear dim}" .. errors) + utils.cprint("${color.warning}checkinfo: ${clear dim}" .. errors) end -- ok? @@ -224,9 +224,9 @@ function sandbox_lib_detect_find_program.main(name, opt) -- trace if option.get("verbose") or opt.verbose then if result then - utils.cprint("checking for the %s ... ${green}%s", name, utils.ifelse(name == result, "ok", result)) + utils.cprint("checking for the %s ... ${color.success}%s", name, utils.ifelse(name == result, "${text.success}", result)) else - utils.cprint("checking for the %s ... ${red}no", name) + utils.cprint("checking for the %s ... ${color.nothing}${text.nothing}", name) end end diff --git a/xmake/themes/emoji/xmake.lua b/xmake/themes/emoji/xmake.lua index b579f742f..d00fd533b 100644 --- a/xmake/themes/emoji/xmake.lua +++ b/xmake/themes/emoji/xmake.lua @@ -26,26 +26,26 @@ theme("emoji") -- the success status - set_text("success", "") - set_color("success", "heavy_check_mark") + set_text("success", "heavy_check_mark") + set_color("success", "") -- the failure status - set_text("failure", "") - set_color("failure", "x") + set_text("failure", "x") + set_color("failure", "") -- the nothing status - set_text("nothing", "") - set_color("nothing", "o") + set_text("nothing", "o") + set_color("nothing", "") -- the error info - set_color("error", "exclamation") - set_color("error.dim", "dim exclamation") - set_color("error.bright", "bright exclamation") + set_color("error", "exclamation red") + set_color("error.dim", "dim exclamation red") + set_color("error.bright", "bright exclamation red") -- the warning info - set_color("warning", "warning") - set_color("warning.dim", "dim warning") - set_color("warning.bright", "bright warning") + set_color("warning", "warning yellow") + set_color("warning.dim", "dim warning yellow") + set_color("warning.bright", "bright warning yellow") -- the building progress set_text("build.progress_format", "[%3d%%]") |
