From e42db579a0e08bd74ae23fa50741bb97cd2a418e Mon Sep 17 00:00:00 2001 From: Yorhel <git@yorhel.nl> Date: Sat, 5 Feb 2022 09:19:11 +0100 Subject: [PATCH] scan: Add UI message when counting hard links That *usually* doesn't take longer than a few milliseconds, but it can take a few seconds for some extremely large dirs, on very slow computers or with optimizations disabled. Better display a message than make it seem as if ncdu has stopped doing anything. --- src/scan.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/scan.zig b/src/scan.zig index 6e9f5ae..b2a6d8b 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -309,7 +309,12 @@ const Context = struct { } fn final(self: *Self) void { - if (self.parents) |_| model.inodes.addAllStats(); + if (self.parents) |_| { + counting_hardlinks = true; + defer counting_hardlinks = false; + main.handleEvent(false, true); + model.inodes.addAllStats(); + } if (self.wr) |wr| { wr.writer().writeByte(']') catch |e| writeErr(e); wr.flush() catch |e| writeErr(e); @@ -977,6 +982,7 @@ pub fn importRoot(path: [:0]const u8, out: ?std.fs.File) void { } var animation_pos: u32 = 0; +var counting_hardlinks: bool = false; var need_confirm_quit = false; fn drawError(err: anyerror) void { @@ -995,10 +1001,17 @@ fn drawError(err: anyerror) void { ui.addstr("Press any key to continue"); } +fn drawCounting() void { + const box = ui.Box.create(4, 25, "Finalizing"); + box.move(2, 2); + ui.addstr("Counting hardlinks..."); +} + fn drawBox() void { ui.init(); const ctx = active_context; if (ctx.fatal_error) |err| return drawError(err); + if (counting_hardlinks) return drawCounting(); const width = ui.cols -| 5; const box = ui.Box.create(10, width, "Scanning..."); box.move(2, 2); @@ -1069,7 +1082,9 @@ pub fn draw() void { .line => { var buf: [256]u8 = undefined; var line: []const u8 = undefined; - if (active_context.parents == null) { + if (counting_hardlinks) { + line = "\x1b7\x1b[JCounting hardlinks...\x1b8"; + } else if (active_context.parents == null) { line = std.fmt.bufPrint(&buf, "\x1b7\x1b[J{s: <63} {d:>9} files\x1b8", .{ ui.shorten(active_context.pathZ(), 63), active_context.items_seen } ) catch return; -- GitLab