Skip to content

Commit b482607

Browse files
committed
fix: download speed only updated when no of bars change
1 parent 68fc9bf commit b482607

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/install.zig

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ pub fn download_tarball(alloc: Allocator, client: *Client, tb_url: []const u8, t
117117

118118
var progress_bar: [150]u8 = ("░" ** 50).*;
119119
var stderr_writer = std.io.getStdErr().writer();
120-
121120
var buff: [1024]u8 = undefined;
122121
var bars: u8 = 0;
123122

@@ -136,15 +135,12 @@ pub fn download_tarball(alloc: Allocator, client: *Client, tb_url: []const u8, t
136135
const pcnt_complete: u8 = @intFromFloat(@round(dlnow * 100 / total_size_double));
137136
var timer = try std.time.Timer.start();
138137
const newbars: u8 = pcnt_complete / 2;
139-
140-
if (newbars > bars) {
141-
for (bars..newbars) |i| {
142-
std.mem.copyForwards(u8, progress_bar[i * 3 .. i * 3 + 3], "█");
143-
}
144-
const dlspeed = @as(f64, @floatFromInt(dlnow)) / 1024 * 8 / @as(f64, @floatFromInt(timer.read()));
145-
try stderr_writer.print("\r\t\x1b[33m{s}\x1b[0m{s} {d}% {d:.1}kb/s", .{ progress_bar[0 .. newbars * 3], progress_bar[newbars * 3 ..], pcnt_complete, dlspeed });
146-
bars = newbars;
138+
for (bars..newbars) |i| {
139+
std.mem.copyForwards(u8, progress_bar[i * 3 .. i * 3 + 3], "█");
147140
}
141+
bars = newbars;
142+
const dlspeed = dlnow / 1024 * 8 / @as(f64, @floatFromInt(timer.read()));
143+
try stderr_writer.print("\r\t\x1b[33m{s}\x1b[0m{s} {d}% {d:.1}kb/s", .{ progress_bar[0 .. newbars * 3], progress_bar[newbars * 3 ..], pcnt_complete, dlspeed });
148144
}
149145
try stderr_writer.print("\n", .{});
150146
try tb_writer.flush();

0 commit comments

Comments
 (0)