summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitty-Cricket Piapiac <kitty@piapiac.org>2023-11-15 00:56:42 +0000
committerKitty-Cricket Piapiac <kitty@piapiac.org>2023-11-15 00:56:42 +0000
commit3ca0fa951817b6fa230e3c37ebd4102e5c29b081 (patch)
treeeee1b8b7c38b179ba19aadd8bd4ec8e39523b7fa
parentc1ab0957ce2e065f2904d6fded7deb3719e4d57f (diff)
allow using text entry to goto dirtrunk
-rw-r--r--pick.zig23
1 files changed, 11 insertions, 12 deletions
diff --git a/pick.zig b/pick.zig
index f11adb3..3b17fbd 100644
--- a/pick.zig
+++ b/pick.zig
@@ -50,8 +50,9 @@ pub const Ctx = struct {
.path = try gpa.alloc(u8, std.fs.MAX_PATH_BYTES),
.filename = try gpa.alloc(u8, std.fs.MAX_PATH_BYTES),
};
+ @memset(ret.path, 0);
const path = ret.path[0..std.fs.MAX_PATH_BYTES];
- ret.path = try std.os.realpath(".", path);
+ _ = try std.os.realpath(".", path);
ret.filename.len = 0;
try ret.list_files();
return ret;
@@ -90,7 +91,10 @@ pub const Ctx = struct {
for (ctx.entries.items) |entry| gpa.free(entry.name);
ctx.entries.clearRetainingCapacity();
- var dir = try std.fs.openIterableDirAbsolute(ctx.path, .{});
+ const len = std.mem.indexOfScalar(u8, ctx.path, 0) orelse ctx.path.len;
+ const path = ctx.path[0..len];
+
+ var dir = try std.fs.openIterableDirAbsolute(path, .{});
defer dir.close();
var iterator = dir.iterate();
@@ -124,23 +128,18 @@ pub const Ctx = struct {
const button_pressed = try dvui.button(@src(), "go", opts.override(.{ .gravity_x = 1 }));
if (button_pressed) {
- try ctx.goto(ctx.path);
+ try ctx.list_files();
}
const text = try dvui.textEntry(@src(), .{ .text = ctx.path }, bg);
defer text.deinit();
}
- fn goto(ctx: *Ctx, dir: []const u8) !void {
- var tmp_buf = std.mem.zeroes([std.fs.MAX_PATH_BYTES]u8);
- var tmp = std.heap.FixedBufferAllocator.init(&tmp_buf);
-
- const path = try std.fs.path.resolve(tmp.allocator(), &.{ ctx.path, dir });
- ctx.path.len = path.len;
-
- const buf = ctx.path.ptr[0..std.fs.MAX_PATH_BYTES];
- @memcpy(buf, &tmp_buf);
+ fn goto(ctx: *Ctx, dirname: []const u8) !void {
+ var dir = try std.fs.openDirAbsoluteZ(@ptrCast(ctx.path), .{});
+ defer dir.close();
+ _ = try dir.realpath(dirname, ctx.path);
try ctx.list_files();
}