summaryrefslogtreecommitdiff
path: root/xmake/modules/utils/progress.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-01 22:53:57 +0800
committerruki <[email protected]>2025-11-01 22:53:57 +0800
commitb3a2dba93a185f205dbd18a154e42da72fdd4881 (patch)
tree64b9c3e123ee03b95ac9cff15ef1e7bfdab3cdd7 /xmake/modules/utils/progress.lua
parent95a282fab0f1a922251426a167939aa2ac9bd5be (diff)
improve to show progress abort
Diffstat (limited to 'xmake/modules/utils/progress.lua')
-rw-r--r--xmake/modules/utils/progress.lua64
1 files changed, 51 insertions, 13 deletions
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)