Differences From Artifact [7133bd835c]:
- File
utils/ofhttp/ProgressBar.m
— part of check-in
[2743414e6e]
at
2015-05-05 20:16:48
on branch trunk
— utils/ofhttp: Only update BPS once per second
Calculating and updating it more frequently results in fluctuations.
The update interval of the progress bar is unchanged. (user: js, size: 4555) [annotate] [blame] [check-ins using]
To Artifact [54fb752c1d]:
- File utils/ofhttp/ProgressBar.m — part of check-in [84f2ba7fbc] at 2015-05-16 18:32:49 on branch trunk — utils/ofhttp: Get terminal width for progress bar (user: js, size: 4794) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <math.h> #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) | > > > > < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <math.h> #ifdef HAVE_SYS_IOCTL_H # include <sys/ioctl.h> #endif #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) #define UPDATE_INTERVAL 0.1 @implementation ProgressBar - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom { self = [super init]; |
︙ | ︙ | |||
79 80 81 82 83 84 85 86 87 | _received = received; } - (void)_drawProgress { uint_fast8_t i; float bars, percent; bars = (float)(_resumedFrom + _received) / | > > > > > > > > > | | | | | | | | | | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | _received = received; } - (void)_drawProgress { uint_fast8_t i; float bars, percent; unsigned short barWidth; #ifdef HAVE_SYS_IOCTL_H struct winsize ws; if (ioctl(0, TIOCGWINSZ, &ws) == 0) barWidth = ws.ws_col - 28; else #endif barWidth = 52; bars = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * 100; [of_stdout writeString: @"\r ▕"]; for (i = 0; i < (uint_fast8_t)bars; i++) [of_stdout writeString: @"█"]; if (bars < barWidth) { float remainder = bars - floorf(bars); if (remainder >= 0.875) [of_stdout writeString: @"▉"]; else if (remainder >= 0.75) [of_stdout writeString: @"▊"]; else if (remainder >= 0.625) [of_stdout writeString: @"▋"]; else if (remainder >= 0.5) [of_stdout writeString: @"▌"]; else if (remainder >= 0.375) [of_stdout writeString: @"▍"]; else if (remainder >= 0.25) [of_stdout writeString: @"▎"]; else if (remainder >= 0.125) [of_stdout writeString: @"▏"]; else [of_stdout writeString: @" "]; for (i = 0; i < barWidth - (uint_fast8_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; if (percent == 100) _BPS = (float)_received / -[_startDate timeIntervalSinceNow]; |
︙ | ︙ |