ObjFW  Diff

Differences From Artifact [54fb752c1d]:

To Artifact [258ce39ec5]:


51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self
					  selector: @selector(draw)
					   repeats: true] retain];
		_BPSTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: 1.0
					    target: self
					  selector: @selector(calculateBPS)

					   repeats: true] retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}







|
>







51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
		    scheduledTimerWithTimeInterval: UPDATE_INTERVAL
					    target: self
					  selector: @selector(draw)
					   repeats: true] retain];
		_BPSTimer = [[OFTimer
		    scheduledTimerWithTimeInterval: 1.0
					    target: self
					  selector: @selector(
							calculateBPSAndETA)
					   repeats: true] retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	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  ▕"];







|


|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	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 - 37;
	else
#endif
		barWidth = 43;

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

	[of_stdout writeString: @"\r  ▕"];
127
128
129
130
131
132
133
134


135












136
137
138
139
140
141
142

		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];













	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];
	else if (_BPS >= KIBIBYTE)
		[of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE];







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







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

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

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

	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];
	else if (_BPS >= KIBIBYTE)
		[of_stdout writeFormat: @"%7.2f KiB/s", _BPS / KIBIBYTE];
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
{
	if (_length > 0)
		[self _drawProgress];
	else
		[self _drawReceived];
}

- (void)calculateBPS
{
	_BPS = (float)(_received - _lastReceived) /
	    -[_lastReceivedDate timeIntervalSinceNow];;


	_lastReceived = _received;
	[_lastReceivedDate release];
	_lastReceivedDate = [[OFDate alloc] init];
}

- (void)stop







|



>







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{
	if (_length > 0)
		[self _drawProgress];
	else
		[self _drawReceived];
}

- (void)calculateBPSAndETA
{
	_BPS = (float)(_received - _lastReceived) /
	    -[_lastReceivedDate timeIntervalSinceNow];;
	_ETA = (double)(_length - _resumedFrom - _resumedFrom) / _BPS;

	_lastReceived = _received;
	[_lastReceivedDate release];
	_lastReceivedDate = [[OFDate alloc] init];
}

- (void)stop