diff options
Diffstat (limited to 'main.zig')
| -rw-r--r-- | main.zig | 53 |
1 files changed, 44 insertions, 9 deletions
@@ -29,7 +29,7 @@ const MAX_FILES: usize = 0x200; fn ticker(io: std.Io, loop: *Loop) void { while (true) { - io.sleep(.fromMilliseconds(2), .awake) catch return; + io.sleep(.fromMilliseconds(200), .awake) catch return; _ = loop.tryPostEvent(.tick) catch return; } } @@ -42,22 +42,21 @@ pub fn main(init: std.process.Init) !void { var tty_buf: [0x10000]u8 = undefined; var lines: [0x1000][0x1000]u8 = undefined; + @memcpy(lines[0][0..2], ".."); + lines[0][2] = 0; const dir = std.Io.Dir.cwd(); - const cwd = try std.Io.Dir.openDir(dir, io, ".", .{ .iterate = true }); - var walk = try cwd.walk(gpa); - defer walk.deinit(); + var cwd = try std.Io.Dir.openDir(dir, io, ".", .{ .iterate = true }); { var i: usize = 0; + var walk = try cwd.walk(gpa); + defer walk.deinit(); while (try walk.next(io)) |e| : (i += 1) { if (i > MAX_FILES) break; - - std.debug.print("path: {s}\n", .{e.path}); - @memcpy(lines[i][0..e.path.len], e.path); - std.debug.dumpHex(lines[i][0..2]); - lines[i][e.path.len] = 0; + @memcpy(lines[i + 1][0..e.path.len], e.path); + lines[i + 1][e.path.len] = 0; } } @@ -75,6 +74,9 @@ pub fn main(init: std.process.Init) !void { try loop.start(); defer loop.stop(); + var tick_task = try io.concurrent(ticker, .{ io, &loop }); + defer tick_task.cancel(io); + while (true) { const event = try loop.nextEvent(); const win = vx.window(); @@ -86,6 +88,7 @@ pub fn main(init: std.process.Init) !void { const len = std.mem.findSentinel(u8, 0, @ptrCast(&lines[i])); _ = win.printSegment(.{ .text = lines[i][0..len] }, .{ .row_offset = @intCast(i), + .col_offset = 4, .wrap = .none, }); } @@ -111,6 +114,38 @@ pub fn main(init: std.process.Init) !void { .wrap = .none, }, ); + + if (cwd.openDir(io, lines[@intCast(m.row)][0..len], .{ .iterate = true })) |d| { + cwd = d; + var walk = try cwd.walk(gpa); + defer walk.deinit(); + var i: usize = 0; + + while (try walk.next(io)) |e| : (i += 1) { + if (i > MAX_FILES) break; + + @memcpy(lines[i + 1][0..e.path.len], e.path); + lines[i + 1][e.path.len] = 0; + } + win.clear(); + // if it's not a dir maybe it's a file + } else |_| { + if (cwd.openFile(io, lines[@intCast(m.row)][0..len], .{ .mode = .read_only })) |f| { + var buf: [0x100]u8 = undefined; + const flen = try f.length(io); + var reader = f.reader(io, &buf); + const str = reader.interface.readAlloc(gpa, flen) catch "empty"; + var iter = std.mem.splitAny(u8, str, "\n"); + var i: usize = 0; + + while (iter.next()) |line| : (i += 1) { + if (i > MAX_FILES) break; + @memcpy(lines[i + 1][0..line.len], line); + lines[i + 1][line.len] = 0; + } + win.clear(); + } else |_| {} + } } }, .winsize => |ws| try vx.resize(gpa, tty.writer(), ws), |
