diff options
| author | Gabriel Schneider <[email protected]> | 2026-06-13 22:26:03 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-06-25 11:23:20 -0300 |
| commit | 7e3240817c888ec3fa4c553cd77695e8d106598f (patch) | |
| tree | b4bee2bee9d6dd2c008ad5eae5ba5f840beb67c5 /main.zig | |
| download | pardes-7e3240817c888ec3fa4c553cd77695e8d106598f.tar.gz pardes-7e3240817c888ec3fa4c553cd77695e8d106598f.zip | |
day-00: basic mouse and showing cwd relative fs
Diffstat (limited to 'main.zig')
| -rw-r--r-- | main.zig | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/main.zig b/main.zig new file mode 100644 index 00000000..e591b7d0 --- /dev/null +++ b/main.zig @@ -0,0 +1,122 @@ +const std = @import("std"); +const vaxis = @import("vaxis"); + +// basic file navigation +// basic shell io +// basic layouting: for now following acme and ad +// * /home/goblin/05-genizah/plan9port/src/cmd/acme +// * /home/goblin/05-genizah/ad +// * /usr/lib/zig +// * ../03-plano +// right click and enter on lines to open files at specified lines + +pub const Command = struct { + prev: ?*Command = null, + pub var value: union(enum) { + close, + ping, + nop, + quit, + tick, + key_press: vaxis.Key, + winsize: vaxis.Winsize, + mouse: vaxis.Mouse, + } = .nop; +}; + +const Loop = vaxis.Loop(@TypeOf(Command.value)); +const MAX_FILES: usize = 0x200; + +fn ticker(io: std.Io, loop: *Loop) void { + while (true) { + io.sleep(.fromMilliseconds(2), .awake) catch return; + _ = loop.tryPostEvent(.tick) catch return; + } +} + +pub fn main(init: std.process.Init) !void { + std.debug.print("hello!\n", .{}); + + const io = init.io; + const gpa = init.gpa; + + var tty_buf: [0x10000]u8 = undefined; + var lines: [0x1000][0x1000]u8 = undefined; + + 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 i: usize = 0; + + 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; + } + } + + var tty = try vaxis.Tty.init(io, &tty_buf); + + var vx = try vaxis.init(io, gpa, init.environ_map, .{}); + defer vx.deinit(gpa, tty.writer()); + + try vx.enterAltScreen(tty.writer()); + defer vx.exitAltScreen(tty.writer()) catch {}; + + try vx.setMouseMode(tty.writer(), true); + + var loop: Loop = .init(io, &tty, &vx); + try loop.start(); + defer loop.stop(); + + while (true) { + const event = try loop.nextEvent(); + const win = vx.window(); + + for (0..MAX_FILES) |i| { + if (i > MAX_FILES) break; + + // const str: [:0]u8 = std.mem.absorbSentinel(&line); + const len = std.mem.findSentinel(u8, 0, @ptrCast(&lines[i])); + _ = win.printSegment(.{ .text = lines[i][0..len] }, .{ + .row_offset = @intCast(i), + .wrap = .none, + }); + } + + switch (event) { + .key_press => |key| { + if (key.matches('c', .{ .ctrl = true })) { + break; + } + }, + .mouse => |m| { + if (m.type == .press) { + // const txt = try std.fmt.allocPrint(gpa, "col={} row={} xo={} yo={}", .{ m.col, m.row, m.xoffset, m.yoffset }); + const len = std.mem.findSentinel(u8, 0, @ptrCast(&lines[@intCast(m.row)])); + _ = win.printSegment( + .{ + .text = lines[@intCast(m.row)][0..len], + .style = .{ .fg = .{ .rgb = .{ 0x00, 0xd0, 0xaa } } }, + }, + .{ + .col_offset = @as(u16, @intCast(m.col)), + .row_offset = @as(u16, @intCast(m.row)), + .wrap = .none, + }, + ); + } + }, + .winsize => |ws| try vx.resize(gpa, tty.writer(), ws), + else => {}, + } + + try vx.render(tty.writer()); + } +} |
