M README.md => README.md +3 -0
@@ 18,6 18,7 @@ to be used as a file selector for other programs.
## TODO:
+* Maybe rename "selection" to "cursor" to not conflict with the "select prompt"?
* refresh dirmap when directory content change
- inotify?
* command/search/select input
@@ 30,6 31,7 @@ to be used as a file selector for other programs.
- preview window should not take up more than 40% of available space
- if terminal wider than high, preview will appear on the right side
- if terminal higher than wide, preview will appear at the bottom
+ - toggle preview with 'p'
* directory preview
- same UI as file preview
- since we also want to preview unvisited directories, DirMap needs a way to
@@ 47,6 49,7 @@ to be used as a file selector for other programs.
* Emacs mode, for those who don't like vim/kakoune inspired keybinds
* When the user presses F1, show a list of all keybinds, Escape goes back to
file view.
+* Maybe set some useful env vars for the launched processes
## Keybinds that still need to be implemented
M src/mode.zig => src/mode.zig +21 -1
@@ 17,6 17,7 @@
const build_options = @import("build_options");
const std = @import("std");
+const ascii = std.ascii;
const math = std.math;
const mem = std.mem;
@@ 24,6 25,14 @@ const Attr = @import("UserInterface.zig").Attr;
const context = &@import("nfm.zig").context;
+const InsertMode = enum {
+ /// Slice is a single word and should be quoted if it contains whitespace.
+ single_word,
+
+ /// Slice should be inserted as is.
+ pure,
+};
+
const MessageLevel = enum {
info,
err,
@@ 86,9 95,20 @@ pub const Mode = union(enum) {
context.mode.user_input.cursor += 1;
}
- pub fn insertSlice(self: *UserInput, slice: []const u8) !void {
+ pub fn insertSlice(self: *UserInput, slice: []const u8, comptime mode: InsertMode) !void {
+ const quote = blk: {
+ if (mode != .single_word) break :blk false;
+ for (slice) |ch| {
+ if (ascii.isSpace(ch)) {
+ try self.insertChar('"');
+ break :blk true;
+ }
+ }
+ break :blk false;
+ };
try self.buffer.insertSlice(context.gpa, self.cursor, slice);
context.mode.user_input.cursor += slice.len;
+ if (quote) try self.insertChar('"');
}
},
M src/nfm.zig => src/nfm.zig +5 -5
@@ 431,15 431,15 @@ fn handleKeyNav(key: u8) !void {
const file = &context.cwd.files.items[context.cwd.selection];
try context.mode.setUserInput(.command);
try context.mode.user_input.insertChar(' ');
- try context.mode.user_input.insertSlice(file.name);
+ try context.mode.user_input.insertSlice(file.name, .single_word);
context.mode.user_input.cursor = 0;
try context.ui.render(false, true);
},
'x' => {
const file = &context.cwd.files.items[context.cwd.selection];
try context.mode.setUserInput(.command);
- try context.mode.user_input.insertSlice("rm ");
- try context.mode.user_input.insertSlice(file.name);
+ try context.mode.user_input.insertSlice("rm ", .pure);
+ try context.mode.user_input.insertSlice(file.name, .single_word);
try context.ui.render(false, true);
},
'X' => {
@@ 450,8 450,8 @@ fn handleKeyNav(key: u8) !void {
'c' => {
const file = &context.cwd.files.items[context.cwd.selection];
try context.mode.setUserInput(.command);
- try context.mode.user_input.insertSlice("mv ");
- try context.mode.user_input.insertSlice(file.name);
+ try context.mode.user_input.insertSlice("mv ", .pure);
+ try context.mode.user_input.insertSlice(file.name, .single_word);
try context.mode.user_input.insertChar(' ');
try context.ui.render(false, true);
},