@@ -149,9 +149,12 @@ private:
149149 void render_line (std::size_t percent, const std::string& info_text);
150150 void render_line_swept (std::size_t frame, const std::string& info_text);
151151
152- // Not a terminal: one start line, then one finish line.
152+ // One line per item in both modes (#734): a terminal redraws it in place
153+ // and ends it with the completion line; elsewhere only the completion
154+ // line is printed. `announce` records the size without printing.
153155 void announce (std::size_t total_bytes);
154156 void finish_plain (std::string_view final_message);
157+ std::string completion (std::string_view final_message) const ;
155158
156159 std::string verb_;
157160 std::string label_;
@@ -608,20 +611,19 @@ ProgressBar::ProgressBar(std::string_view verb, std::string_view label)
608611void ProgressBar::announce (std::size_t total_bytes) {
609612 if (announced_) return ;
610613 announced_ = true ;
611- if (total_bytes > 0 )
612- info (verb_, std::format (" {} ({})" , label_, fmt_bytes (total_bytes)));
613- else
614- info (verb_, label_);
614+ if (total_bytes > lastBytes_) lastBytes_ = total_bytes;
615615}
616616
617- void ProgressBar::finish_plain (std::string_view final_message) {
617+ std::string ProgressBar::completion (std::string_view final_message) const {
618618 const auto secs = std::chrono::duration<double >(
619619 std::chrono::steady_clock::now () - start_).count ();
620620 if (lastBytes_ > 0 )
621- info (verb_, std::format (" {} done, {} in {:.1f}s" , final_message,
622- fmt_bytes (lastBytes_), secs));
623- else
624- info (verb_, std::format (" {} done in {:.1f}s" , final_message, secs));
621+ return std::format (" {} done, {} in {:.1f}s" , final_message, fmt_bytes (lastBytes_), secs);
622+ return std::format (" {} done in {:.1f}s" , final_message, secs);
623+ }
624+
625+ void ProgressBar::finish_plain (std::string_view final_message) {
626+ info (verb_, completion (final_message));
625627}
626628
627629ProgressBar::~ProgressBar () {
@@ -672,7 +674,8 @@ void ProgressBar::update(std::size_t percent) {
672674void ProgressBar::update_bytes (std::size_t current, std::size_t total,
673675 double elapsed_sec) {
674676 if (g_quiet || finished_) return ;
675- if (!live_progress ()) { announce (total); lastBytes_ = current; return ; }
677+ if (!live_progress ()) { announce (total); if (current > lastBytes_) lastBytes_ = current; return ; }
678+ if (current > lastBytes_) lastBytes_ = current;
676679 auto now = std::chrono::steady_clock::now ();
677680 auto pct = total ? (current * 100 / total) : 0 ;
678681 if (pct > 100 ) pct = 100 ;
@@ -696,6 +699,7 @@ void ProgressBar::update_indeterminate(std::size_t current_bytes,
696699 double elapsed_sec) {
697700 if (g_quiet || finished_) return ;
698701 if (!live_progress ()) { announce (0 ); lastBytes_ = current_bytes; return ; }
702+ lastBytes_ = current_bytes;
699703 auto now = std::chrono::steady_clock::now ();
700704 // Same ~80ms throttle as update_bytes(); there is no "100%" early-out here
701705 // because there is no known total.
@@ -723,9 +727,9 @@ void ProgressBar::finish() {
723727 finish_plain (label_);
724728 return ;
725729 }
726- // Clear the line and re-emit as a static info line.
730+ // Clear the line and re-emit it as the completion line.
727731 std::print (" \r\033 [2K" );
728- info (verb_, label_);
732+ info (verb_, completion ( label_) );
729733}
730734
731735void ProgressBar::finish_with (std::string_view final_message) {
@@ -738,7 +742,7 @@ void ProgressBar::finish_with(std::string_view final_message) {
738742 return ;
739743 }
740744 std::print (" \r\033 [2K" );
741- info (verb_, final_message);
745+ info (verb_, completion ( final_message) );
742746}
743747
744748void ProgressBar::finish_failed (std::string_view final_message) {
0 commit comments