diff options
| author | ruki <[email protected]> | 2017-08-18 11:05:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-18 11:05:02 +0800 |
| commit | 7c11f1e69f0aa3bf30410f660dff16a647860320 (patch) | |
| tree | f3c48dc93a2b57c2c44af60b8a60b5df84718c95 | |
| parent | e9a58ed80873622d8de67ff8fad2b3bec868c7e5 (diff) | |
show logo with rainbow
| -rw-r--r-- | xmake/core/base/colors.lua | 29 | ||||
| -rw-r--r-- | xmake/core/base/option.lua | 16 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 4 | ||||
| -rw-r--r-- | xmake/core/main.lua | 32 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 4 |
5 files changed, 67 insertions, 18 deletions
diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index a48dc6df7..d0fedcd81 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -119,7 +119,7 @@ function colors.has256() return os.getenv("ANSICON") end --- support true 24bits colors +-- support 24bits true colors function colors.truecolor() -- this is supported if be not windows @@ -128,6 +128,31 @@ function colors.truecolor() end end +-- make rainbow color code by the index of characters +-- +-- @param index the index of characters +-- @param seed the seed, 0-255, default: random +-- @param freq the frequency, default: 0.1 +-- @param spread the spread, default: 3.0 +-- +-- +function colors.rainbow(index, seed, freq, spread) + + -- init values + seed = seed + freq = freq or 0.1 + spread = spread or 3.0 + index = seed + index / spread + + -- make colors + local red = math.sin(freq * index + 0) * 127 + 128 + local green = math.sin(freq * index + 2 * math.pi / 3) * 127 + 128 + local blue = math.sin(freq * index + 4 * math.pi / 3) * 127 + 128 + + -- make code + return string.format("%d;%d;%d", red, green, blue) +end + -- translate colors from the string -- -- colors: @@ -208,4 +233,4 @@ function colors.translate(str) end -- return module -return colors.translate +return colors diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index e780656d4..c2833d9ad 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -898,13 +898,13 @@ function option.show_menu(task) -- print copyright if menu.copyright then - print(colors(menu.copyright)) + print(colors.translate(menu.copyright)) end -- print usage if taskmenu.usage then print("") - print(colors("${bright}Usage: $${default cyan}" .. taskmenu.usage)) + print(colors.translate("${bright}Usage: $${default cyan}" .. taskmenu.usage)) end -- print description @@ -937,13 +937,13 @@ function option.show_main() -- print copyright if menu.copyright then - print(colors(menu.copyright)) + print(colors.translate(menu.copyright)) end -- print usage if main.usage then print("") - print(colors("${bright}Usage: $${default cyan}" .. main.usage)) + print(colors.translate("${bright}Usage: $${default cyan}" .. main.usage)) end -- print description @@ -993,7 +993,7 @@ function option.show_main() -- print category name print("") - print(colors(string.format("${bright}%s%ss: ", string.sub(categoryname, 1, 1):upper(), string.sub(categoryname, 2)))) + print(colors.translate(string.format("${bright}%s%ss: ", string.sub(categoryname, 1, 1):upper(), string.sub(categoryname, 2)))) -- the padding spaces local padding = 42 @@ -1029,7 +1029,7 @@ function option.show_main() end -- print task line - print(colors(taskline)) + print(colors.translate(taskline)) end end end @@ -1048,7 +1048,7 @@ function option.show_options(options) -- print header print("") - print(colors("${bright}Options: ")) + print(colors.translate("${bright}Options: ")) -- the padding spaces local padding = 42 @@ -1116,7 +1116,7 @@ function option.show_options(options) end -- print option info - print(colors(option_info)) + print(colors.translate(option_info)) -- print more description if exists for i = 6, 64 do diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index 42a55a5e9..5ab310004 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -91,7 +91,7 @@ function utils.cprint(format, ...) assert(format) -- trace - utils._print(colors(string.tryformat(format, ...))) + utils._print(colors.translate(string.tryformat(format, ...))) end -- print format string and colors without newline @@ -101,7 +101,7 @@ function utils.cprintf(format, ...) assert(format) -- trace - utils._iowrite(colors(string.tryformat(format, ...))) + utils._iowrite(colors.translate(string.tryformat(format, ...))) end -- the verbose function diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 227d0e970..08d22bc3a 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -34,6 +34,7 @@ local profiler = require("base/profiler") local deprecated = require("base/deprecated") local privilege = require("base/privilege") local task = require("base/task") +local colors = require("base/colors") local project = require("project/project") local history = require("project/history") local package = require("package/package") @@ -63,14 +64,37 @@ function main._show_logo() > < | \__/ | /_| | < ___/ /_/\_\_|_| |_|\__ \|_|\_\____| - by ruki, ${underline}tboox.org${clear} + by ruki, tboox.org + ]] - ${point_right} ${bright}Manual${clear}: ${underline}http://xmake.io/#/home${clear} - ${pray} ${bright}Donate${clear}: ${underline}http://xmake.io/pages/donation.html#donate${clear} - ]] + -- make rainbow for logo + if colors.truecolor() then + local lines = {} + local seed = 236 + for _, line in ipairs(logo:split("\n")) do + local i = 0 + local line2 = "" + line:gsub(".", function (c) + local code = colors.rainbow(i, seed) + line2 = string.format("%s${%s}%s", line2, code, c) + i = i + 1 + end) + table.insert(lines, line2) + end + logo = table.concat(lines, "\n") + end -- show logo utils.cprint(logo) + + -- define footer + local footer = [[ + ${point_right} ${bright}Manual${clear}: ${underline}http://xmake.io/#/home${clear} + ${pray} ${bright}Donate${clear}: ${underline}http://xmake.io/pages/donation.html#donate${clear} + ]] + + -- show footer + utils.cprint(footer) end -- show help and version info diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 4e3c8858f..c8593098f 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -97,12 +97,12 @@ end -- print format string, the builtin variables and colors with newline function sandbox_utils.cprint(format, ...) - utils._print(colors(vformat(format, ...))) + utils._print(colors.translate(vformat(format, ...))) end -- print format string, the builtin variables and colors without newline function sandbox_utils.cprintf(format, ...) - utils._iowrite(colors(vformat(format, ...))) + utils._iowrite(colors.translate(vformat(format, ...))) end -- print() if enable verbose |
