diff options
| author | ruki <[email protected]> | 2025-11-01 22:53:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-01 22:53:57 +0800 |
| commit | b3a2dba93a185f205dbd18a154e42da72fdd4881 (patch) | |
| tree | 64b9c3e123ee03b95ac9cff15ef1e7bfdab3cdd7 | |
| parent | 95a282fab0f1a922251426a167939aa2ac9bd5be (diff) | |
improve to show progress abort
| -rw-r--r-- | xmake/modules/async/runjobs.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/target.lua | 22 | ||||
| -rw-r--r-- | xmake/modules/utils/progress.lua | 64 | ||||
| -rw-r--r-- | xmake/rules/swift/xmake.lua | 10 |
4 files changed, 63 insertions, 39 deletions
diff --git a/xmake/modules/async/runjobs.lua b/xmake/modules/async/runjobs.lua index be1cc2ad5..286047199 100644 --- a/xmake/modules/async/runjobs.lua +++ b/xmake/modules/async/runjobs.lua @@ -215,7 +215,8 @@ function _consume_jobs_loop(state, run_in_remote) -- stop timer and disable show waitchars first state.stop = true - -- remove wait charactor + -- stop progress + progress.show_abort() if state.show_progress then _print_backchars(state.backnum) state.progress_helper:stop() @@ -371,7 +372,8 @@ function main(name, jobs, opt) co_running:isolate(is_isolated) end - -- remove wait charactor + -- stop progress + progress.show_abort() if state.show_progress then _print_backchars(state.backnum) state.progress_helper:stop() diff --git a/xmake/modules/private/action/build/target.lua b/xmake/modules/private/action/build/target.lua index 315feab61..b4cbd3b0a 100644 --- a/xmake/modules/private/action/build/target.lua +++ b/xmake/modules/private/action/build/target.lua @@ -785,14 +785,9 @@ function run_targetjobs(targets_root, opt) local jobgraph = get_targetjobs(targets_root, opt) if jobgraph and not jobgraph:empty() then local curdir = os.curdir() - async_runjobs(job_kind, jobgraph, {on_exit = function (errors) - import("utils.progress") - if errors then - progress.show_output("") - end - end, - comax = opt.jobs or option.get("jobs") or 1, curdir = curdir, - distcc = opt.distcc, remote_only = opt.remote_only, progress_factor = opt.progress_factor}) + async_runjobs(job_kind, jobgraph, { + comax = opt.jobs or option.get("jobs") or 1, curdir = curdir, + distcc = opt.distcc, remote_only = opt.remote_only, progress_factor = opt.progress_factor}) os.cd(curdir) return true end @@ -805,14 +800,9 @@ function run_filejobs(targets_root, opt) local jobgraph = get_filejobs(targets_root, opt) if jobgraph and not jobgraph:empty() then local curdir = os.curdir() - async_runjobs(job_kind, jobgraph, {on_exit = function (errors) - import("utils.progress") - if errors then - progress.show_output("") - end - end, - comax = opt.jobs or option.get("jobs") or 1, curdir = curdir, - distcc = opt.distcc, remote_only = opt.remote_only, progress_factor = opt.progress_factor}) + async_runjobs(job_kind, jobgraph, { + comax = opt.jobs or option.get("jobs") or 1, curdir = curdir, + distcc = opt.distcc, remote_only = opt.remote_only, progress_factor = opt.progress_factor}) os.cd(curdir) return true end diff --git a/xmake/modules/utils/progress.lua b/xmake/modules/utils/progress.lua index eed316e68..4778c073c 100644 --- a/xmake/modules/utils/progress.lua +++ b/xmake/modules/utils/progress.lua @@ -318,6 +318,23 @@ function _show_progress_with_singlerow_refresh(progress, format, ...) io.flush() end +-- show the current coroutine's progress line (internal helper for multirow mode) +function _show_current_coroutine_progress(maxwidth) + local progress_lineinfos = _g.progress_lineinfos + if progress_lineinfos then + local running = scheduler.co_running() + if running then + local current_lineinfo = progress_lineinfos[running] + if current_lineinfo and current_lineinfo.progress_msg then + local progress_value = _g.last_total_progress_value or 0 + local progress_line = _strip_progress_line(string.format(_get_progress_prefix(), math.floor(progress_value)) .. current_lineinfo.progress_msg, maxwidth) + tty.erase_line_to_end() + cprint(progress_line) + end + end + end +end + -- show the message with progress function show(progress, format, ...) progress = type(progress) == "table" and progress:percent() or math.floor(progress) @@ -353,19 +370,7 @@ function show_output(format, ...) tty.cr() -- show the current task's progress line before the log output - local progress_lineinfos = _g.progress_lineinfos - if progress_lineinfos then - local running = scheduler.co_running() - if running then - local current_lineinfo = progress_lineinfos[running] - if current_lineinfo and current_lineinfo.progress_msg then - local progress_value = _g.last_total_progress_value or 0 - local progress_line = _strip_progress_line(string.format(_get_progress_prefix(), math.floor(progress_value)) .. current_lineinfo.progress_msg, maxwidth) - tty.erase_line_to_end() - cprint(progress_line) - end - end - end + _show_current_coroutine_progress(maxwidth) -- print the log output, which will scroll naturally cprint(format, ...) @@ -377,6 +382,39 @@ function show_output(format, ...) end 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() + local refresh_mode = _g.refresh_mode + if refresh_mode == "multirow" then + -- move to the top of progress area and clear + local linecount = (_g.linecount or 0) + 1 + if linecount > 0 then + tty.cursor_move_up(linecount) + tty.erase_down() + tty.cr() + end + + -- show the current coroutine's progress line before abort + local maxwidth = os.getwinsize().width + _show_current_coroutine_progress(maxwidth) + tty.cursor_show() + + -- reset all global states + _g.refresh_mode = nil + _g.progress_lineinfos = nil + _g.last_total_progress = nil + _g.last_total_progress_value = nil + _g.linecount = 0 + io.flush() + elseif refresh_mode == "singlerow" then + -- clear the current progress line and move to next line + print("") + _g.refresh_mode = nil + io.flush() + end +end + -- get the message text with progress function text(progress, format, ...) progress = type(progress) == "table" and progress:percent() or math.floor(progress) diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua index 10434968b..78f2ebb4f 100644 --- a/xmake/rules/swift/xmake.lua +++ b/xmake/rules/swift/xmake.lua @@ -18,7 +18,7 @@ -- @file xmake.lua -- -rule("swift.interop", function() +rule("swift.interop") set_sourcekinds("sc") add_orders("swift.interop", "swift.build") add_orders("swift.interop", "c++.build") @@ -131,12 +131,7 @@ rule("swift.interop", function() end if opt.progress then - progress.show( - opt.progress, - "${clear}${color.build.target}<%s> generating.swift.header %s", - target:fullname(), - headername - ) + progress.show(opt.progress, "${clear}${color.build.target}<%s> generating.swift.header %s", target:fullname(), headername) end local compinst = import("core.tool.compiler").load("sc") @@ -178,7 +173,6 @@ rule("swift.interop", function() end) end end, { jobgraph = true }) -end) -- define rule: swift.build rule("swift.build") |
