Index: utils/ofhttp/ProgressBar.h ================================================================== --- utils/ofhttp/ProgressBar.h +++ utils/ofhttp/ProgressBar.h @@ -24,14 +24,15 @@ intmax_t _received, _lastReceived, _length, _resumedFrom; OFDate *_startDate, *_lastReceivedDate; OFTimer *_drawTimer, *_BPSTimer; bool _stopped; float _BPS; + double _ETA; } - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom; - (void)setReceived: (intmax_t)received; - (void)draw; -- (void)calculateBPS; +- (void)calculateBPSAndETA; - (void)stop; @end Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -53,11 +53,12 @@ selector: @selector(draw) repeats: true] retain]; _BPSTimer = [[OFTimer scheduledTimerWithTimeInterval: 1.0 target: self - selector: @selector(calculateBPS) + selector: @selector( + calculateBPSAndETA) repeats: true] retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @@ -89,14 +90,14 @@ unsigned short barWidth; #ifdef HAVE_SYS_IOCTL_H struct winsize ws; if (ioctl(0, TIOCGWINSZ, &ws) == 0) - barWidth = ws.ws_col - 28; + barWidth = ws.ws_col - 37; else #endif - barWidth = 52; + barWidth = 43; bars = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * 100; @@ -129,12 +130,26 @@ [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; - if (percent == 100) - _BPS = (float)_received / -[_startDate timeIntervalSinceNow]; + if (percent == 100) { + double timeInterval = -[_startDate timeIntervalSinceNow]; + + _BPS = (float)_received / timeInterval; + _ETA = timeInterval; + } + + if (isinf(_ETA)) + [of_stdout writeString: @"--:--:-- "]; + else if (_ETA >= 99 * 3600) + [of_stdout writeFormat: @"%4.2f d ", _ETA / (24 * 3600)]; + else + [of_stdout writeFormat: @"%2u:%02u:%02u ", + (unsigned char)(_ETA / 3600), + (unsigned char)(_ETA / 60) % 60, + (unsigned char)_ETA % 60]; if (_BPS >= GIBIBYTE) [of_stdout writeFormat: @"%7.2f GiB/s", _BPS / GIBIBYTE]; else if (_BPS >= MEBIBYTE) [of_stdout writeFormat: @"%7.2f MiB/s", _BPS / MEBIBYTE]; @@ -181,14 +196,15 @@ [self _drawProgress]; else [self _drawReceived]; } -- (void)calculateBPS +- (void)calculateBPSAndETA { _BPS = (float)(_received - _lastReceived) / -[_lastReceivedDate timeIntervalSinceNow];; + _ETA = (double)(_length - _resumedFrom - _resumedFrom) / _BPS; _lastReceived = _received; [_lastReceivedDate release]; _lastReceivedDate = [[OFDate alloc] init]; }