summaryrefslogtreecommitdiff
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
parent59c8c59a2983c329118f7839b9949635a85183f5 (diff)
add plain theme
-rw-r--r--xmake/core/_xmake_main.lua4
-rw-r--r--xmake/core/base/colors.lua36
-rw-r--r--xmake/core/base/utils.lua4
-rw-r--r--xmake/core/main.lua12
-rw-r--r--xmake/core/theme/theme.lua16
-rw-r--r--xmake/themes/default/xmake.lua6
-rw-r--r--xmake/themes/plain/xmake.lua32
7 files changed, 86 insertions, 24 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index a56c5a638..7438ab611 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -42,7 +42,5 @@ local main = require("main")
-- the main function
function _xmake_main()
-
- -- done main
- return main.done()
+ return main.entry()
end
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 {}
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 66aa9b606..cba7555d9 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -172,8 +172,8 @@ force to build in current directory via run `xmake -P .`]], os.projectdir())
end
end
--- the main function
-function main.done()
+-- the main entry function
+function main.entry()
-- init
main._init()
@@ -216,6 +216,14 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
return -1
end
+ -- load theme
+ local theme_inst, errors = theme.load(global.get("theme") or "default")
+ if not theme_inst then
+ utils.error(errors)
+ return -1
+ end
+ colors.theme_set(theme_inst)
+
-- show help?
if main._show_help() then
return 0
diff --git a/xmake/core/theme/theme.lua b/xmake/core/theme/theme.lua
index 7d45bf274..5256de788 100644
--- a/xmake/core/theme/theme.lua
+++ b/xmake/core/theme/theme.lua
@@ -29,10 +29,8 @@ local _instance = _instance or {}
-- load modules
local os = require("base/os")
local path = require("base/path")
-local utils = require("base/utils")
local table = require("base/table")
local interpreter = require("base/interpreter")
-local sandbox = require("sandbox/sandbox")
local global = require("base/global")
-- new an instance
@@ -110,12 +108,6 @@ end
-- load the given theme
function theme.load(name)
- -- get it directly from cache dirst
- theme._THEMES = theme._THEMES or {}
- if theme._THEMES[name] then
- return theme._THEMES[name]
- end
-
-- find the theme script path
local scriptpath = nil
for _, dir in ipairs(theme.directories()) do
@@ -157,18 +149,16 @@ function theme.load(name)
return nil, errors
end
- -- save instance to the cache
- theme._THEMES[name] = instance
+ -- save the current theme instance
+ theme._THEME = instance
return instance
end
-- get the given theme configuration
function theme.get(name)
- local instance, errors = theme.load(global.get("theme") or "default")
+ local instance = theme._THEME
if instance then
return instance:get(name)
- else
- os.raise(errors)
end
end
diff --git a/xmake/themes/default/xmake.lua b/xmake/themes/default/xmake.lua
index 547f667b9..a52ac5e14 100644
--- a/xmake/themes/default/xmake.lua
+++ b/xmake/themes/default/xmake.lua
@@ -25,6 +25,8 @@
-- define theme
theme("default")
- -- set error color
- set_color("error", "red")
+ -- set color of the error info
+ set_color("error", "bright red")
+ -- set color of the warning info
+ set_color("warning", "bright yellow")
diff --git a/xmake/themes/plain/xmake.lua b/xmake/themes/plain/xmake.lua
new file mode 100644
index 000000000..fea015678
--- /dev/null
+++ b/xmake/themes/plain/xmake.lua
@@ -0,0 +1,32 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define theme
+theme("plain")
+
+ -- set color of the error info
+ set_color("error", "")
+
+ -- set color of the warning info
+ set_color("warning", "")