diff --git a/ncdu.pod b/ncdu.pod index bd34231f7cefdd8e8998d10f9cc73512c3ed27ce..fe81d9e1fbbfe19aecaa35cfe84ed69c2db22032 100644 --- a/ncdu.pod +++ b/ncdu.pod @@ -227,6 +227,14 @@ browser with the 'g' key. Show (default) or hide the relative size percent column. Can also be toggled in the browser with the 'g' key. +=item B<--graph-style> I<OPTION> + +Change the way that the relative size bar column is drawn. Recognized values +are I<hash> to draw ASCII C<#> characters (most portable), I<half-block> to use +half-block drawing characters (the default) or I<eigth-block> to use +eigth-block drawing characters. Eigth-block characters are the most precise but +may not render correctly in all terminals. + =item B<--shared-column> I<OPTION> Set to I<off> to disable the shared size column for directories, I<shared> diff --git a/src/browser.zig b/src/browser.zig index 44fda3f161b57e81956eda32ddb2753c20ea48a0..d3526ec1f8b371987147423cbaaa9e68aac50ba9 100644 --- a/src/browser.zig +++ b/src/browser.zig @@ -224,14 +224,23 @@ const Row = struct { } if (main.config.show_graph and main.config.show_percent) ui.addch(' '); if (main.config.show_graph) { - const perblock = std.math.divFloor(u64, if (main.config.show_blocks) dir_max_blocks else dir_max_size, bar_size) catch unreachable; - const num = if (main.config.show_blocks) item.blocks else item.size; + var max = if (main.config.show_blocks) dir_max_blocks else dir_max_size; + var num = if (main.config.show_blocks) item.blocks else item.size; + if (max < bar_size) { + max *= bar_size; + num *= bar_size; + } + const perblock = std.math.divFloor(u64, max, bar_size) catch unreachable; var i: u32 = 0; - var siz: u64 = 0; self.bg.fg(.graph); while (i < bar_size) : (i += 1) { - siz = siz +| perblock; - ui.addch(if (siz <= num) '#' else ' '); + const frac = std.math.min(8, (num *| 8) / perblock); + ui.addstr(switch (main.config.graph_style) { + .hash => ([_][:0]const u8{ " ", " ", " ", " ", " ", " ", " ", " ", "#" })[frac], + .half => ([_][:0]const u8{ " ", " ", " ", " ", "▌", "▌", "▌", "▌", "█" })[frac], + .eigth => ([_][:0]const u8{ " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" })[frac], + }); + num -|= perblock; } } self.bg.fg(.default); diff --git a/src/main.zig b/src/main.zig index b064b7e93eb93f672480ea7c4a464994e508a1d2..aabb50a6a4d7543fa26cb9c6c73b162bb3c444ee 100644 --- a/src/main.zig +++ b/src/main.zig @@ -61,6 +61,7 @@ pub const config = struct { pub var show_mtime: bool = false; pub var show_graph: bool = true; pub var show_percent: bool = false; + pub var graph_style: enum { hash, half, eigth } = .half; pub var sort_col: SortCol = .blocks; pub var sort_order: SortOrder = .desc; pub var sort_dirsfirst: bool = false; @@ -181,7 +182,13 @@ fn argConfig(args: *Args, opt: Args.Option) bool { else if (opt.is("--hide-percent")) config.show_percent = false else if (opt.is("--group-directories-first")) config.sort_dirsfirst = true else if (opt.is("--no-group-directories-first")) config.sort_dirsfirst = false - else if (opt.is("--sort")) { + else if (opt.is("--graph-style")) { + const val = args.arg(); + if (std.mem.eql(u8, val, "hash")) config.graph_style = .hash + else if (std.mem.eql(u8, val, "half-block")) config.graph_style = .half + else if (std.mem.eql(u8, val, "eigth-block")) config.graph_style = .eigth + else ui.die("Unknown --graph-style option: {s}.\n", .{val}); + } else if (opt.is("--sort")) { var val: []const u8 = args.arg(); var ord: ?config.SortOrder = null; if (std.mem.endsWith(u8, val, "-asc")) {