Skip to content
Snippets Groups Projects
Commit 5264be76 authored by Yorhel's avatar Yorhel
Browse files

UI: Display shared/unique sizes + hide some columns when no space

parent 59ef5fd2
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,6 @@ Already implemented: ...@@ -48,7 +48,6 @@ Already implemented:
- Add support for separate counting hard links that are shared with other - Add support for separate counting hard links that are shared with other
directories or unique within the directory (issue directories or unique within the directory (issue
[#36](https://code.blicky.net/yorhel/ncdu/issues/36)). [#36](https://code.blicky.net/yorhel/ncdu/issues/36)).
(Implemented in the data model, but not displayed in the UI yet)
- Faster --exclude-kernfs thanks to `statfs()` caching. - Faster --exclude-kernfs thanks to `statfs()` caching.
- Improved handling of Unicode and special characters. - Improved handling of Unicode and special characters.
- Remembers item position when switching directories. - Remembers item position when switching directories.
......
...@@ -14,6 +14,7 @@ var dir_items = std.ArrayList(?*model.Entry).init(main.allocator); ...@@ -14,6 +14,7 @@ var dir_items = std.ArrayList(?*model.Entry).init(main.allocator);
var dir_max_blocks: u64 = 0; var dir_max_blocks: u64 = 0;
var dir_max_size: u64 = 0; var dir_max_size: u64 = 0;
var dir_has_shared: bool = false;
// Index into dir_items that is currently selected. // Index into dir_items that is currently selected.
var cursor_idx: usize = 0; var cursor_idx: usize = 0;
...@@ -124,6 +125,7 @@ pub fn loadDir() void { ...@@ -124,6 +125,7 @@ pub fn loadDir() void {
dir_items.shrinkRetainingCapacity(0); dir_items.shrinkRetainingCapacity(0);
dir_max_size = 1; dir_max_size = 1;
dir_max_blocks = 1; dir_max_blocks = 1;
dir_has_shared = false;
if (dir_parents.top() != model.root) if (dir_parents.top() != model.root)
dir_items.append(null) catch unreachable; dir_items.append(null) catch unreachable;
...@@ -131,13 +133,14 @@ pub fn loadDir() void { ...@@ -131,13 +133,14 @@ pub fn loadDir() void {
while (it) |e| { while (it) |e| {
if (e.blocks > dir_max_blocks) dir_max_blocks = e.blocks; if (e.blocks > dir_max_blocks) dir_max_blocks = e.blocks;
if (e.size > dir_max_size) dir_max_size = e.size; if (e.size > dir_max_size) dir_max_size = e.size;
if (main.config.show_hidden) // fast path const shown = main.config.show_hidden or blk: {
dir_items.append(e) catch unreachable
else {
const excl = if (e.file()) |f| f.excluded else false; const excl = if (e.file()) |f| f.excluded else false;
const name = e.name(); const name = e.name();
if (!excl and name[0] != '.' and name[name.len-1] != '~') break :blk !excl and name[0] != '.' and name[name.len-1] != '~';
dir_items.append(e) catch unreachable; };
if (shown) {
dir_items.append(e) catch unreachable;
if (e.dir()) |d| if (d.shared_blocks > 0 or d.shared_size > 0) { dir_has_shared = true; };
} }
it = e.next; it = e.next;
} }
...@@ -175,15 +178,26 @@ const Row = struct { ...@@ -175,15 +178,26 @@ const Row = struct {
} }
fn size(self: *Self) void { fn size(self: *Self) void {
defer self.col += if (main.config.si) @as(u32, 9) else 10; var width = if (main.config.si) @as(u32, 9) else 10;
if (dir_has_shared and main.config.show_shared != .off)
width += 1 + width;
defer self.col += width;
const item = self.item orelse return; const item = self.item orelse return;
const siz = if (main.config.show_blocks) blocksToSize(item.blocks) else item.size;
var shr = if (item.dir()) |d| (if (main.config.show_blocks) blocksToSize(d.shared_blocks) else d.shared_size) else 0;
if (main.config.show_shared == .unique) shr = saturateSub(siz, shr);
ui.move(self.row, self.col); ui.move(self.row, self.col);
ui.addsize(self.bg, if (main.config.show_blocks) blocksToSize(item.blocks) else item.size); ui.addsize(self.bg, siz);
// TODO: shared sizes if (shr > 0 and main.config.show_shared != .off) {
self.bg.fg(.flag);
ui.addstr(if (main.config.show_shared == .unique) " U" else " S");
ui.addsize(self.bg, shr);
}
} }
fn graph(self: *Self) void { fn graph(self: *Self) void {
if (main.config.show_graph == .off) return; if (main.config.show_graph == .off or self.col + 20 > ui.cols) return;
const bar_size = std.math.max(ui.cols/7, 10); const bar_size = std.math.max(ui.cols/7, 10);
defer self.col += switch (main.config.show_graph) { defer self.col += switch (main.config.show_graph) {
...@@ -223,7 +237,7 @@ const Row = struct { ...@@ -223,7 +237,7 @@ const Row = struct {
} }
fn items(self: *Self) void { fn items(self: *Self) void {
if (!main.config.show_items) return; if (!main.config.show_items or self.col + 10 > ui.cols) return;
defer self.col += 7; defer self.col += 7;
const n = (if (self.item) |d| d.dir() orelse return else return).items; const n = (if (self.item) |d| d.dir() orelse return else return).items;
ui.move(self.row, self.col); ui.move(self.row, self.col);
...@@ -254,7 +268,7 @@ const Row = struct { ...@@ -254,7 +268,7 @@ const Row = struct {
} }
fn mtime(self: *Self) void { fn mtime(self: *Self) void {
if (!main.config.show_mtime) return; if (!main.config.show_mtime or self.col + 37 > ui.cols) return;
defer self.col += 27; defer self.col += 27;
ui.move(self.row, self.col+1); ui.move(self.row, self.col+1);
const ext = (if (self.item) |e| e.ext() else @as(?*model.Ext, null)) orelse dir_parents.top().entry.ext(); const ext = (if (self.item) |e| e.ext() else @as(?*model.Ext, null)) orelse dir_parents.top().entry.ext();
...@@ -469,6 +483,12 @@ pub fn keyInput(ch: i32) void { ...@@ -469,6 +483,12 @@ pub fn keyInput(ch: i32) void {
.percent => .both, .percent => .both,
.both => .off, .both => .off,
}, },
// TODO: This key binding is not final! I'd rather add a menu selection thing for advanced settings rather than risk running out of more keys.
'u' => main.config.show_shared = switch (main.config.show_shared) {
.off => .shared,
.shared => .unique,
.unique => .off,
},
else => {} else => {}
} }
......
...@@ -51,6 +51,7 @@ pub const config = struct { ...@@ -51,6 +51,7 @@ pub const config = struct {
pub var show_hidden: bool = true; pub var show_hidden: bool = true;
pub var show_blocks: bool = true; pub var show_blocks: bool = true;
pub var show_shared: enum { off, shared, unique } = .shared;
pub var show_items: bool = false; pub var show_items: bool = false;
pub var show_mtime: bool = false; pub var show_mtime: bool = false;
pub var show_graph: enum { off, graph, percent, both } = .graph; pub var show_graph: enum { off, graph, percent, both } = .graph;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment