ObjFW  Diff

Differences From Artifact [814de8c246]:

To Artifact [8b9c4a1fb2]:


31
32
33
34
35
36
37

38
39
40
41
42
43

44
45
46
47
48
49
50
#define KIBIBYTE (1024)

#define UPDATE_INTERVAL 0.1

@implementation ProgressBar
- (instancetype)initWithLength: (unsigned long long)length
		   resumedFrom: (unsigned long long)resumedFrom

{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();


		_length = length;
		_resumedFrom = resumedFrom;
		_startDate = [[OFDate alloc] init];
		_lastReceivedDate = [[OFDate alloc] init];
		_drawTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self







>






>







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#define KIBIBYTE (1024)

#define UPDATE_INTERVAL 0.1

@implementation ProgressBar
- (instancetype)initWithLength: (unsigned long long)length
		   resumedFrom: (unsigned long long)resumedFrom
		    useUnicode: (bool)useUnicode
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		_useUnicode = useUnicode;
		_length = length;
		_resumedFrom = resumedFrom;
		_startDate = [[OFDate alloc] init];
		_lastReceivedDate = [[OFDate alloc] init];
		_drawTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self
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
136
137
138
139
		barWidth = 43;

	bars = (float)(_resumedFrom + _received) /
	    (float)(_resumedFrom + _length) * barWidth;
	percent = (float)(_resumedFrom + _received) /
	    (float)(_resumedFrom + _length) * 100;


	[of_stdout writeString: @"\r  ▕"];

	for (size_t i = 0; i < (size_t)bars; i++)
		[of_stdout writeString: @"█"];
	if (bars < barWidth) {
		float rem = bars - truncf(bars);

		if (rem >= 0.875)
			[of_stdout writeString: @"▉"];
		else if (rem >= 0.75)
			[of_stdout writeString: @"▊"];
		else if (rem >= 0.625)
			[of_stdout writeString: @"▋"];
		else if (rem >= 0.5)
			[of_stdout writeString: @"▌"];
		else if (rem >= 0.375)
			[of_stdout writeString: @"▍"];
		else if (rem >= 0.25)
			[of_stdout writeString: @"▎"];
		else if (rem >= 0.125)
			[of_stdout writeString: @"▏"];
		else
			[of_stdout writeString: @" "];

		for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++)
			[of_stdout writeString: @" "];
	}

	[of_stdout writeFormat: @"▏ %,6.2f%% ", percent];
























	if (percent == 100) {
		double timeInterval = -_startDate.timeIntervalSinceNow;

		_BPS = (float)_received / (float)timeInterval;
		_ETA = timeInterval;
	}







>
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
		barWidth = 43;

	bars = (float)(_resumedFrom + _received) /
	    (float)(_resumedFrom + _length) * barWidth;
	percent = (float)(_resumedFrom + _received) /
	    (float)(_resumedFrom + _length) * 100;

	if (_useUnicode) {
		[of_stdout writeString: @"\r  ▕"];

		for (size_t i = 0; i < (size_t)bars; i++)
			[of_stdout writeString: @"█"];
		if (bars < barWidth) {
			float rem = bars - truncf(bars);

			if (rem >= 0.875)
				[of_stdout writeString: @"▉"];
			else if (rem >= 0.75)
				[of_stdout writeString: @"▊"];
			else if (rem >= 0.625)
				[of_stdout writeString: @"▋"];
			else if (rem >= 0.5)
				[of_stdout writeString: @"▌"];
			else if (rem >= 0.375)
				[of_stdout writeString: @"▍"];
			else if (rem >= 0.25)
				[of_stdout writeString: @"▎"];
			else if (rem >= 0.125)
				[of_stdout writeString: @"▏"];
			else
				[of_stdout writeString: @" "];

			for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++)
				[of_stdout writeString: @" "];
		}

		[of_stdout writeFormat: @"▏ %,6.2f%% ", percent];
	} else {
		[of_stdout writeString: @"\r  ["];

		for (size_t i = 0; i < (size_t)bars; i++)
			[of_stdout writeString: @"#"];
		if (bars < barWidth) {
			float rem = bars - truncf(bars);

			if (rem >= 0.75)
				[of_stdout writeString: @"O"];
			else if (rem >= 0.5)
				[of_stdout writeString: @"o"];
			else if (rem >= 0.25)
				[of_stdout writeString: @"."];
			else
				[of_stdout writeString: @" "];

			for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++)
				[of_stdout writeString: @" "];
		}

		[of_stdout writeFormat: @"] %,6.2f%% ", percent];
	}

	if (percent == 100) {
		double timeInterval = -_startDate.timeIntervalSinceNow;

		_BPS = (float)_received / (float)timeInterval;
		_ETA = timeInterval;
	}