summaryrefslogtreecommitdiff
path: root/xmake/modules/utils/progress.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-28 23:21:16 +0800
committerruki <[email protected]>2025-10-29 10:37:58 +0800
commitbfb71ee9883ac2d0e115913f089bef36899645c2 (patch)
treeb0889ff13263af9bf23a48f5220228493232957b /xmake/modules/utils/progress.lua
parent9773535b0c6989dffcc01d42035c0d50f58ddd51 (diff)
sort progress
Diffstat (limited to 'xmake/modules/utils/progress.lua')
-rw-r--r--xmake/modules/utils/progress.lua24
1 files changed, 18 insertions, 6 deletions
diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua
index 6dc90d309..28e1a7eb9 100644
--- a/xmake/modules/utils/progress.lua
+++ b/xmake/modules/utils/progress.lua
@@ -163,14 +163,21 @@ function _show_progress_with_multirow_refresh(progress, format, ...)
local current_time = os.mclock()
if lineinfo == nil then
_g.linecount = linecount + 1
- local subprogress_line = _strip_progress_line(" ${dim}0.00s " .. progress_msg)
- lineinfo = {progress_line = subprogress_line, running = running, start_time = current_time}
+ lineinfo = {start_time = current_time, spent_time = 0}
progress_lineinfos[running] = lineinfo
else
- local subprogress_line = _strip_progress_line(vformat(" ${dim}%0.02fs ", (current_time - lineinfo.start_time) / 1000) .. progress_msg)
- lineinfo.progress_line = subprogress_line
+ lineinfo.spent_time = current_time - lineinfo.start_time
lineinfo.start_time = current_time
end
+ local timecolor = ""
+ local spent_time = lineinfo.spent_time
+ if spent_time > 1000 then
+ timecolor = "${magenta}"
+ elseif spent_time > 500 then
+ timecolor = "${yellow}"
+ end
+ local subprogress_line = _strip_progress_line(vformat(" ${dim}> %s%0.02fs${clear}${dim} ", timecolor, spent_time / 1000) .. progress_msg)
+ lineinfo.progress_line = subprogress_line
local maxwidth = os.getwinsize().width
if not is_first and linecount > 0 then
@@ -181,10 +188,15 @@ function _show_progress_with_multirow_refresh(progress, format, ...)
tty.erase_line_to_start().cr()
cprint(progress_line)
- for _, progress_lineinfo in table.orderpairs(progress_lineinfos) do
+ local lineinfos = {}
+ for _, progress_lineinfo in pairs(progress_lineinfos) do
+ table.insert(lineinfos, progress_lineinfo)
+ end
+ table.sort(lineinfos, function (a, b) return a.spent_time > b.spent_time end)
+ for _, lineinfo in ipairs(lineinfos) do
tty.cursor_move_to_col(maxwidth)
tty.erase_line_to_start().cr()
- cprint(progress_lineinfo.progress_line)
+ cprint(lineinfo.progress_line)
end
if is_finished then