@@ -55,8 +55,9 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
5555
5656 std::vector<std::unique_ptr<indicators::ProgressBar>> items;
5757 indicators::show_console_cursor (false );
58- auto handle_message = [this , &bars, &items,
59- event_type](const std::string& message) {
58+ auto start = std::chrono::steady_clock::now ();
59+ auto handle_message = [this , &bars, &items, event_type,
60+ start](const std::string& message) {
6061 CTL_INF (message);
6162
6263 auto pad_string = [](const std::string& str,
@@ -80,7 +81,7 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
8081 if (ev.download_task_ .type != event_type) {
8182 return ;
8283 }
83-
84+ auto now = std::chrono::steady_clock::now ();
8485 if (!bars) {
8586 bars = std::make_unique<
8687 indicators::DynamicProgress<indicators::ProgressBar>>();
@@ -91,7 +92,7 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
9192 indicators::option::End{" ]" },
9293 indicators::option::PrefixText{pad_string (Repo2Engine (i.id ))},
9394 indicators::option::ForegroundColor{indicators::Color::white},
94- indicators::option::ShowRemainingTime{true }));
95+ indicators::option::ShowRemainingTime{false }));
9596 bars->push_back (*(items.back ()));
9697 }
9798 }
@@ -101,22 +102,34 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
101102 uint64_t downloaded = it.downloadedBytes .value_or (0u );
102103 uint64_t total =
103104 it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
105+ auto d = std::chrono::duration_cast<std::chrono::seconds>(now - start)
106+ .count ();
107+ uint64_t bytes_per_sec = downloaded / (d + 1 );
108+ std::string time_remaining;
109+ if (downloaded == total || bytes_per_sec == 0 ) {
110+ time_remaining = " 00m:00s" ;
111+ } else {
112+ time_remaining = format_utils::TimeDownloadFormat (
113+ (total - downloaded) / bytes_per_sec);
114+ }
115+
104116 (*bars)[i].set_option (indicators::option::PrefixText{
105117 pad_string (Repo2Engine (it.id )) +
106118 std::to_string (int (static_cast <double >(downloaded) / total * 100 )) +
107119 ' %' });
108120 (*bars)[i].set_progress (
109121 int (static_cast <double >(downloaded) / total * 100 ));
110122 (*bars)[i].set_option (indicators::option::PostfixText{
123+ time_remaining + " " +
111124 format_utils::BytesToHumanReadable (downloaded) + " /" +
112125 format_utils::BytesToHumanReadable (total)});
113126 } else if (ev.type_ == DownloadStatus::DownloadSuccess) {
114127 uint64_t total =
115128 it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
116129 (*bars)[i].set_progress (100 );
117130 auto total_str = format_utils::BytesToHumanReadable (total);
118- (*bars)[i].set_option (
119- indicators::option::PostfixText{ total_str + " /" + total_str});
131+ (*bars)[i].set_option (indicators::option::PostfixText{
132+ " 00m:00s " + total_str + " /" + total_str});
120133 (*bars)[i].set_option (indicators::option::PrefixText{
121134 pad_string (Repo2Engine (it.id )) + " 100%" });
122135 (*bars)[i].set_progress (100 );
0 commit comments