summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-09 11:58:10 +0800
committerruki <[email protected]>2021-10-09 11:58:10 +0800
commita01e17a5049bdd02ddc2514bd47af74cf2ff802d (patch)
tree83cea0cf9fa564bd0bbbddb35a366b64a404635e /xmake/modules
parent59498b047190411a144f821a5cc40174faeaaa9a (diff)
move private.utils.progress to utils.progress
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/ar.lua2
-rw-r--r--xmake/modules/core/tools/cl.lua2
-rw-r--r--xmake/modules/core/tools/gcc.lua2
-rw-r--r--xmake/modules/core/tools/nvcc.lua2
-rw-r--r--xmake/modules/core/tools/sdcc.lua2
-rw-r--r--xmake/modules/private/action/build/object.lua2
-rw-r--r--xmake/modules/private/action/require/impl/install_packages.lua2
-rw-r--r--xmake/modules/private/action/require/impl/package.lua2
-rw-r--r--xmake/modules/private/async/runjobs.lua4
-rw-r--r--xmake/modules/private/utils/batchcmds.lua2
-rw-r--r--xmake/modules/utils/progress.lua139
11 files changed, 150 insertions, 11 deletions
diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua
index dc858a19e..abb1e9695 100644
--- a/xmake/modules/core/tools/ar.lua
+++ b/xmake/modules/core/tools/ar.lua
@@ -20,7 +20,7 @@
-- imports
import("core.tool.compiler")
-import("private.utils.progress")
+import("utils.progress")
-- init it
function init(self)
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 54eafe227..efea29a14 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -26,7 +26,7 @@ import("core.project.project")
import("core.language.language")
import("private.tools.vstool")
import("private.tools.cl.parse_include")
-import("private.utils.progress")
+import("utils.progress")
-- init it
function init(self)
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index c6422d204..2cf31e2dc 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -27,7 +27,7 @@ import("core.project.config")
import("core.project.project")
import("core.language.language")
import("private.tools.ccache")
-import("private.utils.progress")
+import("utils.progress")
-- init it
function init(self)
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 25a589124..2aad54096 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -26,7 +26,7 @@ import("core.project.project")
import("core.platform.platform")
import("core.language.language")
import("private.tools.ccache")
-import("private.utils.progress")
+import("utils.progress")
-- init it
function init(self)
diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua
index 526254fe7..82d6cd78a 100644
--- a/xmake/modules/core/tools/sdcc.lua
+++ b/xmake/modules/core/tools/sdcc.lua
@@ -21,7 +21,7 @@
-- imports
import("core.base.option")
import("core.base.global")
-import("private.utils.progress")
+import("utils.progress")
-- init it
function init(self)
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index 50397cda4..7a99de91e 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -25,7 +25,7 @@ import("core.tool.compiler")
import("core.project.depend")
import("private.tools.ccache")
import("private.async.runjobs")
-import("private.utils.progress")
+import("utils.progress")
-- do build file
function _do_build_file(target, sourcefile, opt)
diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua
index c8bdefbb1..714b98461 100644
--- a/xmake/modules/private/action/require/impl/install_packages.lua
+++ b/xmake/modules/private/action/require/impl/install_packages.lua
@@ -25,7 +25,7 @@ import("core.base.scheduler")
import("core.project.project")
import("core.base.tty")
import("private.async.runjobs")
-import("private.utils.progress")
+import("utils.progress")
import("actions.install", {alias = "action_install"})
import("actions.download", {alias = "action_download"})
import("net.fasturl")
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index b048b7818..f00d796f6 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -23,7 +23,7 @@ import("core.base.semver")
import("core.base.option")
import("core.base.global")
import("core.base.hashset")
-import("private.utils.progress")
+import("utils.progress")
import("core.cache.memcache")
import("core.project.project")
import("core.project.config")
diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua
index 0361399dc..a4ea2bc10 100644
--- a/xmake/modules/private/async/runjobs.lua
+++ b/xmake/modules/private/async/runjobs.lua
@@ -20,7 +20,7 @@
-- imports
import("core.base.scheduler")
-import("private.utils.progress")
+import("utils.progress")
-- print back characters
function _print_backchars(backnum)
@@ -37,7 +37,7 @@ end
-- e.g.
-- runjobs("test", function (index) print("hello") end, {total = 100, comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end})
-- runjobs("test", function () os.sleep(10000) end, { progress = true })
--- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module private.utils.progress
+-- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module utils.progress
--
-- local jobs = jobpool.new()
-- local root = jobs:addjob("job/root", function (idx, total)
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua
index 946135a87..34dd5d583 100644
--- a/xmake/modules/private/utils/batchcmds.lua
+++ b/xmake/modules/private/utils/batchcmds.lua
@@ -28,7 +28,7 @@ import("core.theme.theme")
import("core.tool.linker")
import("core.tool.compiler")
import("core.language.language")
-import("private.utils.progress", {alias = "progress_utils"})
+import("utils.progress", {alias = "progress_utils"})
-- define module
local batchcmds = batchcmds or object { _init = {"_TARGET", "_CMDS", "_DEPS", "_tip"}}
diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua
new file mode 100644
index 000000000..074046a69
--- /dev/null
+++ b/xmake/modules/utils/progress.lua
@@ -0,0 +1,139 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed 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-present, TBOOX Open Source Group.
+--
+-- @author OpportunityLiu
+-- @file progress.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.object")
+import("core.base.colors")
+import("core.base.tty")
+import("core.theme.theme")
+
+-- define module
+local process = process or object { _init = { "_RUNNING", "_INDEX", "_STREAM", "_OPT" } }
+
+-- stop the progress indicator, clear written frames
+function process:stop()
+ if self._RUNNING ~= 0 then
+ self:clear()
+ self._RUNNING = 0
+ self._INDEX = 0
+ end
+end
+
+function process:_clear()
+ if self._RUNNING == 1 then
+ tty.erase_line_to_end()
+ self._RUNNING = 2
+ return true
+ end
+end
+
+-- clear previous frame of the progress indicator
+function process:clear()
+ if self:_clear() then
+ self._STREAM:flush()
+ end
+end
+
+-- write next frame of the progress indicator
+function process:write()
+ local chars = self._OPT.chars[self._INDEX % #self._OPT.chars + 1]
+ tty.cursor_and_attrs_save()
+ self._STREAM:write(chars)
+ self._STREAM:flush()
+ tty.cursor_and_attrs_restore()
+ self._INDEX = self._INDEX + 1
+ self._RUNNING = 1
+end
+
+-- check if the progress indicator is running
+function process:running()
+ return self._RUNNING and true or false
+end
+
+-- showing progress line without scroll?
+function showing_without_scroll()
+ return _g.showing_without_scroll
+end
+
+-- show the message with process
+function show(progress, format, ...)
+ progress = math.floor(progress)
+ local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
+ if option.get("verbose") then
+ cprint(progress_prefix .. "${dim}" .. format, progress, ...)
+ else
+ local is_scroll = _g.is_scroll
+ if is_scroll == nil then
+ is_scroll = theme.get("text.build.progress_style") == "scroll"
+ _g.is_scroll = is_scroll
+ end
+ if is_scroll then
+ cprint(progress_prefix .. format, progress, ...)
+ else
+ tty.erase_line_to_start().cr()
+ local msg = vformat(progress_prefix .. format, progress, ...)
+ local msg_plain = colors.translate(msg, {plain = true})
+ local maxwidth = os.getwinsize().width
+ if #msg_plain <= maxwidth then
+ cprintf(msg)
+ else
+ -- windows width is too small? strip the partial message in middle
+ local partlen = math.floor(maxwidth / 2) - 3
+ local sep = msg_plain:sub(partlen + 1, #msg_plain - partlen - 1)
+ local split = msg:split(sep, {plain = true, strict = true})
+ cprintf(table.concat(split, "..."))
+ end
+ if math.floor(progress) == 100 then
+ print("")
+ _g.showing_without_scroll = false
+ else
+ _g.showing_without_scroll = true
+ end
+ io.flush()
+ end
+ end
+end
+
+-- get the message text with process
+function text(progress, format, ...)
+ progress = math.floor(progress)
+ local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
+ if option.get("verbose") then
+ return string.format(progress_prefix .. "${dim}" .. format, progress, ...)
+ else
+ return string.format(progress_prefix .. format, progress, ...)
+ end
+end
+
+-- build a progress indicator
+-- @params stream - stream to write to, will use io.stdout if not provided
+-- @params opt - options
+-- - chars - an array of chars for progress indicator
+function new(stream, opt)
+
+ -- set default values
+ stream = stream or io.stdout
+ opt = opt or {}
+ if opt.chars == nil or #opt.chars == 0 then
+ opt.chars = theme.get("text.spinner.chars")
+ end
+ return process {_OPT = opt, _STREAM = stream, _RUNNING = 0, _INDEX = 0}
+end