diff options
| author | ruki <[email protected]> | 2019-01-02 00:57:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-01 23:47:08 +0800 |
| commit | 59c8c59a2983c329118f7839b9949635a85183f5 (patch) | |
| tree | 8828214363911c982c819abc611e11e669b6031e | |
| parent | 38e38540325ff07453a324e8049ed575fad8cb8d (diff) | |
add default theme
| -rw-r--r-- | xmake/actions/config/main.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/global/main.lua | 7 | ||||
| -rw-r--r-- | xmake/actions/global/menuconf.lua | 12 | ||||
| -rw-r--r-- | xmake/actions/global/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/global.lua | 19 | ||||
| -rw-r--r-- | xmake/core/main.lua | 9 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 2 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/global.lua | 5 | ||||
| -rw-r--r-- | xmake/core/theme/theme.lua | 176 | ||||
| -rw-r--r-- | xmake/themes/default/xmake.lua | 30 |
11 files changed, 230 insertions, 41 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index ac73addbe..03a274617 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -185,9 +185,6 @@ function main() -- enter cache scope cache.enter("local.config") - -- load global configure - global.load() - -- load the project configure -- -- priority: option > option_cache > global > option_default > config_check > project_check > config_cache diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 928621da3..5f4fa25ff 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -39,9 +39,8 @@ function main() -- -- priority: option > option_default > config_check > global_cache -- - local configcache = false - if not option.get("clean") then - configcache = global.load() + if option.get("clean") then + global.clear() end -- override the option configure @@ -64,7 +63,7 @@ function main() end -- check the global configure - if changed or not configcache then + if changed or option.get("clean") then global.check() end diff --git a/xmake/actions/global/menuconf.lua b/xmake/actions/global/menuconf.lua index e5e543797..a039ed350 100644 --- a/xmake/actions/global/menuconf.lua +++ b/xmake/actions/global/menuconf.lua @@ -51,7 +51,7 @@ function app:init() self:insert(self:mconfdialog()) -- load configs - self:load(not option.get("clean")) + self:load() end -- get menu config dialog @@ -277,11 +277,11 @@ function app:_save_configs(configs) end -- load configs from options -function app:load(cache) +function app:load() - -- load config from cache - if cache then - cache = global.load() + -- clean the global configuration + if option.get("clean") then + global.clear() end -- clear configs first @@ -293,7 +293,7 @@ function app:load(cache) self:mconfdialog():load(configs) -- the previous config is only for loading menuconf, so clear config now - if cache then + if option.get("clean") then global.clear() end end diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua index 78f5e8fc1..6bf86efa8 100644 --- a/xmake/actions/global/xmake.lua +++ b/xmake/actions/global/xmake.lua @@ -49,6 +49,7 @@ task("global") , {nil, "menu", "k", nil, "Configure with a menu-driven user interface." } , {category = "."} + , {nil, "theme", "kv", "default","The theme name." } , {nil, "debugger", "kv", "auto", "The Debugger Program Path." } -- show platform menu options diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua index 410c824f4..d86572a7c 100644 --- a/xmake/core/base/global.lua +++ b/xmake/core/base/global.lua @@ -39,8 +39,6 @@ end -- get the current given configure function global.get(name) - - -- get it local value = nil if global._CONFIGS then value = global._CONFIGS[name] @@ -48,8 +46,6 @@ function global.get(name) value = nil end end - - -- get it return value end @@ -96,8 +92,6 @@ function global.options() configs[name] = value end end - - -- get it return configs end @@ -109,34 +103,27 @@ function global.directory() return global._ROOTDIR end --- load the global configure +-- load the global configuration function global.load() -- load configure from the file first - local ok = false local filepath = global._file() if os.isfile(filepath) then -- load configs local results, errors = io.load(filepath) - - -- error? if not results then - utils.error(errors) - return false + return false, errors end -- merge the configure for name, value in pairs(results) do if global.get(name) == nil then global.set(name, value) - ok = true end end end - - -- ok? - return ok + return true end -- save the global configure diff --git a/xmake/core/main.lua b/xmake/core/main.lua index abe233720..66aa9b606 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -31,11 +31,13 @@ local log = require("base/log") local path = require("base/path") local utils = require("base/utils") local option = require("base/option") +local global = require("base/global") 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 theme = require("theme/theme") local project = require("project/project") local history = require("project/history") @@ -207,6 +209,13 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. profiler:start() end + -- load global configuration + ok, errors = global.load() + if not ok then + utils.error(errors) + return -1 + end + -- show help? if main._show_help() then return 0 diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 4a22ce926..5ddc16117 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -48,7 +48,7 @@ function _instance.new(name, info, rootdir) local instance = table.inherit(_instance) -- init instance - instance._name = name + instance._name = name instance._NAME = name instance._INFO = info instance._ROOTDIR = rootdir diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a128f5fd8..8a189da49 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -176,7 +176,6 @@ end -- get platform apis function platform._apis() - return { values = @@ -300,15 +299,11 @@ function platform.load(plat) -- save instance to the cache platform._PLATFORMS[plat] = instance - - -- ok return instance end --- get the given platform configure +-- get the given platform configuration function platform.get(name, plat) - - -- get the current platform configure local instance, errors = platform.load(plat) if instance then return instance:get(name) diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index 3cec5c7f4..8c011e9d2 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -57,11 +57,6 @@ function sandbox_core_base_global.dump() global.dump() end --- load the configure -function sandbox_core_base_global.load() - return global.load() -end - -- save the configure function sandbox_core_base_global.save() diff --git a/xmake/core/theme/theme.lua b/xmake/core/theme/theme.lua new file mode 100644 index 000000000..7d45bf274 --- /dev/null +++ b/xmake/core/theme/theme.lua @@ -0,0 +1,176 @@ +--!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 theme.lua +-- + +-- define module +local theme = theme or {} +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 +function _instance.new(name, info, rootdir) + + -- new an instance + local instance = table.inherit(_instance) + + -- init instance + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir + + -- ok + return instance +end + +-- get theme name +function _instance:name() + return self._NAME +end + +-- get the theme configuration +function _instance:get(name) + return self._INFO[name] +end + +-- the interpreter +function theme._interpreter() + + -- the interpreter has been initialized? return it directly + if theme._INTERPRETER then + return theme._INTERPRETER + end + + -- init interpreter + local interp = interpreter.new() + assert(interp) + + -- define apis + interp:api_define(theme._apis()) + + -- save interpreter + theme._INTERPRETER = interp + + -- ok? + return interp +end + +-- get theme apis +function theme._apis() + return + { + keyvalues = + { + -- theme.set_xxx + "theme.set_color" + } + } +end + +-- get theme directories +function theme.directories() + + -- init directories + local dirs = theme._DIRS or { path.join(global.directory(), "themes") + , path.join(os.programdir(), "themes") + } + + -- save directories to cache + theme._DIRS = dirs + return dirs +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 + scriptpath = path.join(dir, name, "xmake.lua") + if os.isfile(scriptpath) then + break + end + end + + -- not exists? uses the default theme + if not scriptpath or not os.isfile(scriptpath) then + scriptpath = path.join(os.programdir(), "themes", "default", "xmake.lua") + end + + -- get interpreter + local interp = theme._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + + -- load theme + local results, errors = interp:make("theme", true, false) + if not results and os.isfile(scriptpath) then + return nil, errors + end + + -- get result + local result = results[name] + if not result then + return nil, string.format("the theme %s not found!", name) + end + + -- new an instance + local instance, errors = _instance.new(name, result, interp:rootdir()) + if not instance then + return nil, errors + end + + -- save instance to the cache + theme._THEMES[name] = instance + return instance +end + +-- get the given theme configuration +function theme.get(name) + local instance, errors = theme.load(global.get("theme") or "default") + if instance then + return instance:get(name) + else + os.raise(errors) + end +end + +-- return module +return theme diff --git a/xmake/themes/default/xmake.lua b/xmake/themes/default/xmake.lua new file mode 100644 index 000000000..547f667b9 --- /dev/null +++ b/xmake/themes/default/xmake.lua @@ -0,0 +1,30 @@ +--!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("default") + + -- set error color + set_color("error", "red") + |
