Skip to content
Snippets Groups Projects
Commit 7d290595 authored by Yorhel's avatar Yorhel
Browse files

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.
parent edf48f6f
No related branches found
No related tags found
No related merge requests found
......@@ -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")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment