Newer
Older
fn drawCounting() void {
const box = ui.Box.create(4, 25, "Finalizing");
box.move(2, 2);
ui.addstr("Counting hardlinks...");
}
const ctx = active_context;
if (ctx.fatal_error) |err| return drawError(err);
if (counting_hardlinks) return drawCounting();
const box = ui.Box.create(10, width, "Scanning...");
box.move(2, 2);
ui.addstr("Total items: ");
ui.addnum(.default, ctx.items_seen);
// TODO: Should display the size of the dir-to-be-refreshed on refreshing, not the root.
ui.addsize(.default, util.blocksToSize(model.root.entry.blocks +| model.inodes.total_blocks));
}
box.move(3, 2);
ui.addstr("Current item: ");
ui.addstr(ui.shorten(ui.toUtf8(ctx.pathZ()), width -| 18));
if (ctx.last_error) |path| {
box.move(5, 2);
ui.style(.bold);
ui.addstr("Warning: ");
ui.style(.default);
ui.addstr("error scanning ");
ui.addstr(ui.shorten(ui.toUtf8(path), width -| 28));
box.move(6, 3);
ui.addstr("some directory sizes may not be correct.");
}
ui.addstr("Press ");
ui.style(.key);
ui.addch('y');
ui.style(.default);
ui.addstr(" to confirm");
} else {
ui.addstr("Press ");
ui.style(.key);
ui.addch('q');
ui.style(.default);
ui.addstr(" to abort");
}
if (main.config.update_delay < std.time.ns_per_s and width > 40) {
const txt = "Scanning...";
animation_pos += 1;
if (animation_pos >= txt.len*2) animation_pos = 0;
if (animation_pos < txt.len) {
var i: u32 = 0;
box.move(8, 2);
while (i <= animation_pos) : (i += 1) ui.addch(txt[i]);
} else {
var i: u32 = txt.len-1;
while (i > animation_pos-txt.len) : (i -= 1) {
box.move(8, 2+i);
ui.addch(txt[i]);
}
}
}
}
if (active_context.fatal_error != null and main.config.scan_ui.? != .full)
ui.die("Error reading {s}: {s}\n", .{ active_context.last_error.?, ui.errorString(active_context.fatal_error.?) });
.none => {},
.line => {
var buf: [256]u8 = undefined;
var line: []const u8 = undefined;
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 }
const r = ui.FmtSize.fmt(util.blocksToSize(model.root.entry.blocks));
line = std.fmt.bufPrint(&buf, "\x1b7\x1b[J{s: <51} {d:>9} files / {s}{s}\x1b8",
.{ ui.shorten(active_context.pathZ(), 51), active_context.items_seen, r.num(), r.unit }
) catch return;
}
_ = std.io.getStdErr().write(line) catch {};
},
if (active_context.fatal_error != null) {
if (main.state == .scan) ui.quit()
else main.state = .browse;
return;
}
if (need_confirm_quit) {
switch (ch) {
'y', 'Y' => if (need_confirm_quit) ui.quit(),
else => need_confirm_quit = false,
}
return;
}
'q' => if (main.config.confirm_quit) { need_confirm_quit = true; } else ui.quit(),
else => need_confirm_quit = false,