summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-10-18 22:33:45 +0800
committerruki <[email protected]>2019-10-18 09:22:31 +0800
commit2b075f93f9a3111d3c0439f13f77c079ba8c2ac0 (patch)
treec0262cd6c6ae9e6b3cbc2459587ed533590aa440
parent7ef0d3eac5452a5c71f0ad9f7010d376c1f70e4c (diff)
improve install tips
-rw-r--r--xmake/actions/require/impl/action/download.lua35
-rw-r--r--xmake/actions/require/impl/action/install.lua25
-rw-r--r--xmake/actions/require/impl/package.lua9
-rw-r--r--xmake/core/base/process.lua21
-rw-r--r--xmake/core/sandbox/modules/utils.lua25
5 files changed, 60 insertions, 55 deletions
diff --git a/xmake/actions/require/impl/action/download.lua b/xmake/actions/require/impl/action/download.lua
index a7b222009..d956eb319 100644
--- a/xmake/actions/require/impl/action/download.lua
+++ b/xmake/actions/require/impl/action/download.lua
@@ -25,23 +25,6 @@ import("net.http")
import("devel.git")
import("utils.archive")
--- empty chars
-function _emptychars()
-
- -- get left width
- local width = os.getwinsize()["width"] - 1
- if not width or width <= 0 then
- width = 64
- end
-
- -- make empty chars
- local emptychars = ""
- for i = 1, width do
- emptychars = emptychars .. " "
- end
- return emptychars
-end
-
-- checkout codes from git
function _checkout(package, url, sourcedir, url_alias)
@@ -52,7 +35,7 @@ function _checkout(package, url, sourcedir, url_alias)
-- clean the previous build files
git.clean({repodir = packagedir, force = true})
- printf("\r" .. _emptychars() .. "\r")
+ utils.clearline()
return
end
@@ -81,8 +64,8 @@ function _checkout(package, url, sourcedir, url_alias)
os.mv(sourcedir .. ".tmp", sourcedir)
-- trace
- printf("\r" .. _emptychars())
- cprint("\r${yellow} => ${clear}clone %s %s .. ${color.success}${text.success}", url, package:version_str())
+ utils.clearline()
+ cprint("${yellow} => ${clear}clone %s %s .. ${color.success}${text.success}", url, package:version_str())
end
-- download codes from ftp/http/https
@@ -134,11 +117,9 @@ function _download(package, url, sourcedir, url_alias, url_excludes)
package:originfile_set(path.absolute(packagefile))
-- trace
+ utils.clearline()
if not cached then
- printf("\r" .. _emptychars())
- cprint("\r${yellow} => ${clear}download %s .. ${color.success}${text.success}", url)
- else
- printf("\r" .. _emptychars() .. "\r")
+ cprint("${yellow} => ${clear}download %s .. ${color.success}${text.success}", url)
end
end
@@ -219,11 +200,11 @@ function main(package)
end
-- trace
- printf("\r" .. _emptychars())
+ utils.clearline()
if git.checkurl(url) then
- cprint("\r${yellow} => ${clear}clone %s %s .. ${color.failure}${text.failure}", url, package:version_str())
+ cprint("${yellow} => ${clear}clone %s %s .. ${color.failure}${text.failure}", url, package:version_str())
else
- cprint("\r${yellow} => ${clear}download %s .. ${color.failure}${text.failure}", url)
+ cprint("${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 15114f83d..d6ec9434c 100644
--- a/xmake/actions/require/impl/action/install.lua
+++ b/xmake/actions/require/impl/action/install.lua
@@ -26,23 +26,6 @@ import("test")
import("patch")
import(".utils.filter")
--- empty chars
-function _emptychars()
-
- -- get left width
- local width = os.getwinsize()["width"] - 1
- if not width or width <= 0 then
- width = 64
- end
-
- -- make empty chars
- local emptychars = ""
- for i = 1, width do
- emptychars = emptychars .. " "
- end
- return emptychars
-end
-
-- patch pkgconfig if not exists
function _patch_pkgconfig(package)
@@ -216,8 +199,8 @@ function main(package)
package:envs_leave()
-- trace
- printf("\r" .. _emptychars())
- cprint("\r${yellow} => ${clear}install %s %s .. ${color.success}${text.success}", package:name(), package:version_str() or "")
+ utils.clearline()
+ cprint("${yellow} => ${clear}install %s %s .. ${color.success}${text.success}", package:name(), package:version_str() or "")
end,
catch
@@ -235,8 +218,8 @@ function main(package)
end
-- trace
- printf("\r" .. _emptychars())
- cprint("\r${yellow} => ${clear}install %s %s .. ${color.failure}${text.failure}", package:name(), package:version_str() or "")
+ utils.clearline()
+ cprint("${yellow} => ${clear}install %s %s .. ${color.failure}${text.failure}", package:name(), package:version_str() or "")
-- leave the package environments
package:envs_leave()
diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua
index 929397f8a..553b041ec 100644
--- a/xmake/actions/require/impl/package.lua
+++ b/xmake/actions/require/impl/package.lua
@@ -510,7 +510,7 @@ end
function _install_packages(packages_install, packages_download)
local waitindex = 0
- local waitchars = {'\\', '|', '/', '-'}
+ local waitchars = {'\\', '-', '/', '|'}
local packages_installing = {}
local packages_downloading = {}
local packages_pending = table.copy(packages_install)
@@ -609,7 +609,7 @@ function _install_packages(packages_install, packages_download)
packages_installing[index] = nil
packages_downloading[index] = nil
- end, #packages_install, (option.get("verbose") or option.get("diagnosis")) and 1 or 4, 300, function (indices)
+ end, #packages_install, (option.get("verbose") or option.get("diagnosis")) and 1 or 4, 300, function (indices, tips)
-- do not print progress info if be verbose
if option.get("verbose") then
@@ -634,14 +634,15 @@ function _install_packages(packages_install, packages_download)
end
-- trace
- cprintf("\r${yellow} => ${clear}")
+ utils.clearline()
+ cprintf("${yellow} => ${clear}")
if #downloading > 0 then
cprintf("downloading ${magenta}%s${clear}", table.concat(downloading, ", "))
end
if #installing > 0 then
cprintf("%sinstalling ${magenta}%s${clear}", #downloading > 0 and ", " or "", table.concat(installing, ", "))
end
- cprintf(" .. %s", waitchars[waitindex + 1])
+ cprintf(" .. ${dim}%s${clear}%s", tips and (tips .. " ") or "", waitchars[waitindex + 1])
io.flush()
end)
end
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua
index 1e4fe5434..35f74dbde 100644
--- a/xmake/core/base/process.lua
+++ b/xmake/core/base/process.lua
@@ -79,7 +79,7 @@ end
-- tostring(subprocess)
function _subprocess:__tostring()
- return "subprocess: " .. self:name()
+ return "<subprocess: " .. self:name() .. ">"
end
-- gc(subprocess)
@@ -163,7 +163,7 @@ function process.asyncrun(task, waitchars)
-- trace
local waitindex = 0
- local waitchars = waitchars or {'\\', '|', '/', '-'}
+ local waitchars = waitchars or {'\\', '-', '/', '|'}
utils.printf(waitchars[waitindex + 1])
io.flush()
@@ -242,7 +242,22 @@ function process.runjobs(jobfunc, total, comax, timeout, timer)
-- timer is triggered? call timer
if timer and os.mclock() - time > timeout then
- timer(indices)
+ local tips = nil
+ if #procs > 0 then
+ local names = {}
+ for _, proc in ipairs(procs) do
+ table.insert(names, proc:name())
+ end
+ names = table.unique(names)
+ if #names > 0 then
+ names = table.concat(names, ",")
+ if #names > 16 then
+ names = names:sub(1, 16) .. ".."
+ end
+ tips = string.format("(%d/%s)", #procs, names)
+ end
+ end
+ timer(indices, tips)
time = os.mclock()
end
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index f71d2a72b..9773d92a5 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -167,6 +167,31 @@ function sandbox_utils.dprintf(format, ...)
end
end
+-- clear the current terminal line
+function sandbox_utils.clearline()
+
+ -- get empty line chars
+ local emptychars = sandbox_utils._EMPTYCHARS
+ if not emptychars then
+
+ -- get left width
+ local width = os.getwinsize()["width"] - 1
+ if not width or width <= 0 then
+ width = 64
+ end
+
+ -- make empty chars
+ emptychars = ""
+ for i = 1, width do
+ emptychars = emptychars .. " "
+ end
+ sandbox_utils._EMPTYCHARS = emptychars
+ end
+
+ -- clear line
+ sandbox_utils.printf("\r" .. emptychars .. "\r")
+end
+
-- assert
function sandbox_utils.assert(value, format, ...)