summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-20 00:46:17 +0800
committerruki <[email protected]>2025-11-20 00:46:17 +0800
commitbb23918bcc9423cecc98275759d529adf41f4ca5 (patch)
tree2665c846d3f89604fdfb24aa88ff94af0e74f803
parentd4f99444640e55c2170c7407ca567af2047dc558 (diff)
add
-rw-r--r--xmake/modules/private/check/checkers/clang/tidy.lua15
-rw-r--r--xmake/modules/utils/progress.lua21
-rw-r--r--xmake/plugins/format/main.lua19
3 files changed, 49 insertions, 6 deletions
diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua
index edd671db3..66c9feb87 100644
--- a/xmake/modules/private/check/checkers/clang/tidy.lua
+++ b/xmake/modules/private/check/checkers/clang/tidy.lua
@@ -155,6 +155,19 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
-- run clang-tidy
local analyze_time = os.mclock()
+ local runjobs_opt = {
+ total = #sourcefiles,
+ comax = opt.jobs or os.default_njob(),
+ showtips = false
+ }
+ -- Only set timer for multirow refresh mode
+ if progress.is_multirow() then
+ runjobs_opt.timeout = 500
+ runjobs_opt.on_timer = function (running_indices)
+ -- Periodically refresh multirow progress to update elapsed time
+ progress.refresh()
+ end
+ end
runjobs("checker.tidy", function (index, total, job_opt)
local sourcefile = sourcefiles[index]
local tidy_argv = table.join(argv, {sourcefile})
@@ -163,7 +176,7 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
projectdir = projectdir,
progress = job_opt.progress
})
- end, {total = #sourcefiles, comax = opt.jobs or os.default_njob(), showtips = false})
+ end, runjobs_opt)
analyze_time = os.mclock() - analyze_time
progress.show(100, "${color.success}clang-tidy analyzed %d files, spent %.3fs", #sourcefiles, analyze_time / 1000)
end
diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua
index 4778c073c..c8846e033 100644
--- a/xmake/modules/utils/progress.lua
+++ b/xmake/modules/utils/progress.lua
@@ -212,6 +212,12 @@ function _redraw_multirow_progress(maxwidth)
return
end
+ -- move cursor back to the top of progress area to avoid scrolling
+ local linecount = _g.linecount or 0
+ if linecount > 0 then
+ tty.cursor_move_up(linecount + 1)
+ end
+
-- redraw the total progress line
tty.erase_line().cr()
cprint(last_total_progress)
@@ -382,6 +388,21 @@ function show_output(format, ...)
end
end
+-- refresh the multirow progress display to update elapsed time
+-- this is useful for long-running tasks to keep the elapsed time updated
+function refresh()
+ local refresh_mode = _g.refresh_mode
+ if refresh_mode == "multirow" then
+ local maxwidth = os.getwinsize().width
+ _redraw_multirow_progress(maxwidth)
+ end
+end
+
+-- check if multirow refresh mode is enabled
+function is_multirow()
+ return _is_multirow_refresh()
+end
+
-- abort the progress display mode, used for error exit or early termination
-- this function cleans up the progress display area and restores the terminal state
function show_abort()
diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua
index 743f67eb5..e8b962e2e 100644
--- a/xmake/plugins/format/main.lua
+++ b/xmake/plugins/format/main.lua
@@ -216,16 +216,25 @@ function main()
jobs = os.default_njob()
end
local format_time = os.mclock()
+ local runjobs_opt = {
+ total = #sourcefiles,
+ comax = jobs,
+ showtips = false
+ }
+ -- Only set timer for multirow refresh mode
+ if progress.is_multirow() then
+ runjobs_opt.timeout = 500
+ runjobs_opt.on_timer = function (running_indices)
+ -- Periodically refresh multirow progress to update elapsed time
+ progress.refresh()
+ end
+ end
runjobs("clang-format", function (index, total, opt)
local sourcefile = sourcefiles[index]
local format_argv = table.join(argv, {sourcefile})
progress.show(opt.progress, "clang-format.formatting %s", sourcefile)
os.execv(clang_format.program, format_argv, {curdir = projectdir})
- end, {
- total = #sourcefiles,
- comax = jobs,
- showtips = false
- })
+ end, runjobs_opt)
format_time = os.mclock() - format_time
progress.show(100, "${color.success}clang-format formatted %d files, spent %.3fs", #sourcefiles, format_time / 1000)
end