mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-15 18:18:41 -09:00
Disable refresh, delete and link list when reading from file
TODO: Add an option to re-enable these features by importing the file into RAM?
This commit is contained in:
parent
ad166de925
commit
17e384b485
1 changed files with 34 additions and 14 deletions
|
|
@ -386,7 +386,7 @@ const Row = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
var state: enum { main, quit, help, info } = .main;
|
var state: enum { main, quit, help, info } = .main;
|
||||||
var message: ?[:0]const u8 = null;
|
var message: ?[]const [:0]const u8 = null;
|
||||||
|
|
||||||
const quit = struct {
|
const quit = struct {
|
||||||
fn draw() void {
|
fn draw() void {
|
||||||
|
|
@ -443,7 +443,7 @@ const info = struct {
|
||||||
}
|
}
|
||||||
state = .info;
|
state = .info;
|
||||||
tab = t;
|
tab = t;
|
||||||
if (tab == .links and links == null) {
|
if (tab == .links and links == null and !main.config.binreader) {
|
||||||
var list = std.ArrayList(*model.Link).init(main.allocator);
|
var list = std.ArrayList(*model.Link).init(main.allocator);
|
||||||
var l = e.?.link().?;
|
var l = e.?.link().?;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
@ -459,6 +459,11 @@ const info = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn drawLinks(box: ui.Box, row: *u32, rows: u32, cols: u32) void {
|
fn drawLinks(box: ui.Box, row: *u32, rows: u32, cols: u32) void {
|
||||||
|
if (main.config.binreader) {
|
||||||
|
box.move(2, 2);
|
||||||
|
ui.addstr("This feature is not available when reading from file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const numrows = rows -| 4;
|
const numrows = rows -| 4;
|
||||||
if (links_idx < links_top) links_top = links_idx;
|
if (links_idx < links_top) links_top = links_idx;
|
||||||
if (links_idx >= links_top + numrows) links_top = links_idx - numrows + 1;
|
if (links_idx >= links_top + numrows) links_top = links_idx - numrows + 1;
|
||||||
|
|
@ -581,7 +586,7 @@ const info = struct {
|
||||||
// for each item. Think it's better to have a dynamic height based on
|
// for each item. Think it's better to have a dynamic height based on
|
||||||
// terminal size and scroll if the content doesn't fit.
|
// terminal size and scroll if the content doesn't fit.
|
||||||
const rows = 5 // border + padding + close message
|
const rows = 5 // border + padding + close message
|
||||||
+ if (tab == .links) 8 else
|
+ if (tab == .links and !main.config.binreader) 8 else
|
||||||
4 // name + type + disk usage + apparent size
|
4 // name + type + disk usage + apparent size
|
||||||
+ (if (e.ext() != null) @as(u32, 1) else 0) // last modified
|
+ (if (e.ext() != null) @as(u32, 1) else 0) // last modified
|
||||||
+ (if (e.link() != null) @as(u32, 1) else 0) // link count
|
+ (if (e.link() != null) @as(u32, 1) else 0) // link count
|
||||||
|
|
@ -622,7 +627,7 @@ const info = struct {
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tab == .links) {
|
if (tab == .links and !main.config.binreader) {
|
||||||
if (keyInputSelection(ch, &links_idx, links.?.items.len, 5))
|
if (keyInputSelection(ch, &links_idx, links.?.items.len, 5))
|
||||||
return true;
|
return true;
|
||||||
if (ch == 10) { // Enter - go to selected entry
|
if (ch == 10) { // Enter - go to selected entry
|
||||||
|
|
@ -801,7 +806,10 @@ pub fn draw() void {
|
||||||
ui.addch('?');
|
ui.addch('?');
|
||||||
ui.style(.hd);
|
ui.style(.hd);
|
||||||
ui.addstr(" for help");
|
ui.addstr(" for help");
|
||||||
if (main.config.imported) {
|
if (main.config.binreader) {
|
||||||
|
ui.move(0, ui.cols -| 11);
|
||||||
|
ui.addstr("[from file]");
|
||||||
|
} else if (main.config.imported) {
|
||||||
ui.move(0, ui.cols -| 10);
|
ui.move(0, ui.cols -| 10);
|
||||||
ui.addstr("[imported]");
|
ui.addstr("[imported]");
|
||||||
} else if (!main.config.can_delete.?) {
|
} else if (!main.config.can_delete.?) {
|
||||||
|
|
@ -859,10 +867,14 @@ pub fn draw() void {
|
||||||
.info => info.draw(),
|
.info => info.draw(),
|
||||||
}
|
}
|
||||||
if (message) |m| {
|
if (message) |m| {
|
||||||
const box = ui.Box.create(6, 60, "Message");
|
const box = ui.Box.create(@intCast(m.len + 5), 60, "Message");
|
||||||
box.move(2, 2);
|
i = 2;
|
||||||
ui.addstr(m);
|
for (m) |ln| {
|
||||||
box.move(4, 33);
|
box.move(i, 2);
|
||||||
|
ui.addstr(ln);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
box.move(i+1, 33);
|
||||||
ui.addstr("Press any key to continue");
|
ui.addstr("Press any key to continue");
|
||||||
}
|
}
|
||||||
if (sel_row > 0) ui.move(sel_row, 0);
|
if (sel_row > 0) ui.move(sel_row, 0);
|
||||||
|
|
@ -913,8 +925,12 @@ pub fn keyInput(ch: i32) void {
|
||||||
'?' => state = .help,
|
'?' => state = .help,
|
||||||
'i' => if (dir_items.items.len > 0) info.set(dir_items.items[cursor_idx], .info),
|
'i' => if (dir_items.items.len > 0) info.set(dir_items.items[cursor_idx], .info),
|
||||||
'r' => {
|
'r' => {
|
||||||
if (!main.config.can_refresh.?)
|
if (main.config.binreader)
|
||||||
message = "Directory refresh feature disabled."
|
message = &.{"Refresh feature is not available when reading from file."}
|
||||||
|
else if (!main.config.can_refresh.? and main.config.imported)
|
||||||
|
message = &.{"Refresh feature disabled.", "Re-run with --enable-refresh to enable this option."}
|
||||||
|
else if (!main.config.can_refresh.?)
|
||||||
|
message = &.{"Directory refresh feature disabled."}
|
||||||
else {
|
else {
|
||||||
main.state = .refresh;
|
main.state = .refresh;
|
||||||
sink.global.sink = .mem;
|
sink.global.sink = .mem;
|
||||||
|
|
@ -923,14 +939,18 @@ pub fn keyInput(ch: i32) void {
|
||||||
},
|
},
|
||||||
'b' => {
|
'b' => {
|
||||||
if (!main.config.can_shell.?)
|
if (!main.config.can_shell.?)
|
||||||
message = "Shell feature disabled."
|
message = &.{"Shell feature disabled.", "Re-run with --enable-shell to enable this option."}
|
||||||
else
|
else
|
||||||
main.state = .shell;
|
main.state = .shell;
|
||||||
},
|
},
|
||||||
'd' => {
|
'd' => {
|
||||||
if (dir_items.items.len == 0) {
|
if (dir_items.items.len == 0) {
|
||||||
} else if (!main.config.can_delete.?)
|
} else if (main.config.binreader)
|
||||||
message = "Deletion feature disabled."
|
message = &.{"File deletion is not available when reading from file."}
|
||||||
|
else if (!main.config.can_delete.? and main.config.imported)
|
||||||
|
message = &.{"File deletion is disabled.", "Re-run with --enable-delete to enable this option."}
|
||||||
|
else if (!main.config.can_delete.?)
|
||||||
|
message = &.{"File deletion is disabled."}
|
||||||
else if (dir_items.items[cursor_idx]) |e| {
|
else if (dir_items.items[cursor_idx]) |e| {
|
||||||
main.state = .delete;
|
main.state = .delete;
|
||||||
const next =
|
const next =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue