@@ -202,11 +202,22 @@ function _display_subprocess_lines(order_lineinfos)
202202 linecount = linecount + 1
203203 end
204204 end
205+ -- clear the left lines
206+ local left_linecount = # order_lineinfos - linecount
207+ if left_linecount > 0 then
208+ for i = 1 , left_linecount do
209+ tty .erase_line ().cr ()
210+ print (" " )
211+ end
212+ tty .cursor_move_up (left_linecount )
213+ end
205214 _g .linecount = linecount
206215end
207216
208217-- redraw the multirow progress area (internal helper)
209- function _redraw_multirow_progress (maxwidth )
218+ -- @param maxwidth: window width
219+ -- @param current_time: optional current time (to avoid repeated os.mclock() calls)
220+ function _redraw_multirow_progress (maxwidth , current_time )
210221 local last_total_progress = _g .last_total_progress
211222 if not last_total_progress then
212223 return
@@ -217,7 +228,9 @@ function _redraw_multirow_progress(maxwidth)
217228 cprint (last_total_progress )
218229
219230 -- build and display the subprocess lines
220- local current_time = os .mclock ()
231+ if not current_time then
232+ current_time = os .mclock ()
233+ end
221234 local order_lineinfos = _build_ordered_subprocess_lineinfos (maxwidth , current_time )
222235 _display_subprocess_lines (order_lineinfos )
223236 io.flush ()
@@ -266,6 +279,7 @@ function _show_progress_with_multirow_refresh(progress, format, ...)
266279 -- save the total progress line and progress value for potential redraw in show_output
267280 _g .last_total_progress = progress_line
268281 _g .last_total_progress_value = progress
282+ _g .last_show_time = current_time
269283
270284 -- update the current progress info
271285 local current_lineinfo = progress_lineinfos [running ]
@@ -382,6 +396,41 @@ function show_output(format, ...)
382396 end
383397end
384398
399+ -- check if multirow refresh mode is enabled
400+ function is_multirow ()
401+ return _is_multirow_refresh ()
402+ end
403+
404+ -- refresh the multirow progress display to update elapsed time
405+ -- this is useful for long-running tasks to keep the elapsed time updated
406+ function refresh ()
407+ local refresh_mode = _g .refresh_mode
408+ if refresh_mode == " multirow" then
409+ -- get current time once and reuse it
410+ local current_time = os .mclock ()
411+
412+ -- only refresh if more than 500ms has passed since last show
413+ -- this avoids too frequent refreshes
414+ local last_show_time = _g .last_show_time
415+ if last_show_time then
416+ local elapsed = current_time - last_show_time
417+ if elapsed <= 500 then
418+ return
419+ end
420+ end
421+
422+ -- move cursor back to the top of progress area to avoid scrolling
423+ local linecount = _g .linecount or 0
424+ if linecount > 0 then
425+ tty .cursor_move_up (linecount + 1 )
426+ end
427+
428+ -- redraw the progress area immediately, passing current_time to avoid repeated calls
429+ local maxwidth = os .getwinsize ().width
430+ _redraw_multirow_progress (maxwidth , current_time )
431+ end
432+ end
433+
385434-- abort the progress display mode, used for error exit or early termination
386435-- this function cleans up the progress display area and restores the terminal state
387436function show_abort ()
0 commit comments