mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
Add --graph-style option and Unicode graph drawing
And also adjust the graph width calculation to do a better job when the largest item is smaller than the number of columns used for the graph, which would previously draw either nothing (if size = 0) or a full bar (if size > 0). Fixes #172.
This commit is contained in:
parent
edf48f6f11
commit
7d2905952d
3 changed files with 30 additions and 6 deletions
8
ncdu.pod
8
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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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")) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue