diff options
| author | Gabriel Schneider <[email protected]> | 2026-06-19 16:48:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-06-19 16:48:33 -0300 |
| commit | 7f2ad9b0d84a5a2b07bb728fdc47a6f9c19e8cdf (patch) | |
| tree | 49fd19e771301389e38dd788405544b9c2ac144a | |
| parent | ffed14b9857b53a2aae4a0c39dee47949f1331f2 (diff) | |
| download | pardes-7f2ad9b0d84a5a2b07bb728fdc47a6f9c19e8cdf.tar.gz pardes-7f2ad9b0d84a5a2b07bb728fdc47a6f9c19e8cdf.zip | |
clean version
| -rw-r--r-- | main.zig | 139 |
1 files changed, 74 insertions, 65 deletions
@@ -2,6 +2,18 @@ const std = @import("std"); const vaxis = @import("vaxis"); const ghostty_vt = @import("ghostty-vt"); +extern "c" fn forkpty( + amaster: *c_int, + name: ?[*:0]u8, + termp: ?*const anyopaque, + winp: ?*const std.posix.winsize, +) c_int; + +extern "c" fn execvp( + file: [*:0]const u8, + argv: [*:null]const ?[*:0]const u8, +) c_int; + // basic file navigation // basic shell io // basic layouting: for now following acme and ad @@ -35,91 +47,88 @@ fn ticker(io: std.Io, loop: *Loop) void { } } +fn fork_pty(argv: [:0]const u8, ws: std.posix.winsize) std.Io.File { + var master: c_int = undefined; + const pid = forkpty(&master, null, null, &ws); + if (pid == 0) { + _ = execvp(argv, &.{}); + std.process.exit(0); + } + + // not sure about the false here + const f: std.Io.File = .{ .handle = master, .flags = .{ .nonblocking = false } }; + return f; +} + +const nrows = 40; +const ncols = 6; + pub fn main(init: std.process.Init) !void { std.debug.print("hello!\n", .{}); - const io = init.io; const gpa = init.gpa; - var t: ghostty_vt.Terminal = try .init(gpa, .{ - .cols = 6, - .rows = 40, + const master = fork_pty("/usr/bin/bash", .{ + .row = nrows, + .col = ncols, + .xpixel = 0, + .ypixel = 0, }); - defer t.deinit(gpa); - try t.printString("hello there!\nhowdy!"); - const str = try t.plainString(gpa); + var read_buf: [0x100]u8 = undefined; + var reader = master.readerStreaming(io, &read_buf); + try io.sleep(.fromMilliseconds(100), .real); + const str = try reader.interface.readAlloc(gpa, 2); + std.debug.print("\n\nreader: {} {s}\n\n", .{ reader.size orelse 1234, str }); - 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; + var term: ghostty_vt.Terminal = try .init(gpa, .{ + .cols = ncols, + .rows = nrows, + }); + defer term.deinit(gpa); + var stream = term.vtStream(); + defer stream.deinit(); + try term.printString("hello there!\nhowdy!"); - while (try walk.next(io)) |e| : (i += 1) { - if (i > MAX_FILES) break; + // const str = try term.plainString(gpa); - 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_buf: [0x10000]u8 = undefined; 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.enterAltScreen(tty.writer()); + // defer vx.exitAltScreen(tty.writer()) catch {}; - try vx.setMouseMode(tty.writer(), true); + // try vx.setMouseMode(tty.writer(), true); - var loop: Loop = .init(io, &tty, &vx); - try loop.start(); - defer loop.stop(); + // var loop: Loop = .init(io, &tty, &vx); + // try loop.start(); + // defer loop.stop(); - while (true) { - const event = try loop.nextEvent(); - const win = vx.window(); - const win_child = win.child(.{ .border = .{ .where = .all }, .height = 8, .width = 42 }); - _ = win_child.printSegment(.{ .text = "hey" }, .{}); + // while (true) { + // const event = try loop.nextEvent(); + // const win = vx.window(); + // const win_child = win.child(.{ .border = .{ .where = .all }, .height = 8, .width = 42 }); + // _ = win_child.printSegment(.{ .text = "hey" }, .{}); - switch (event) { - .key_press => |key| { - if (key.matches('c', .{ .ctrl = true })) { - break; - } - }, - .mouse => |m| { - _ = win.printSegment(.{ .text = str }, .{ .col_offset = 1, .row_offset = 1 }); + // switch (event) { + // .key_press => |key| { + // if (key.matches('c', .{ .ctrl = true })) { + // break; + // } + // }, + // .mouse => |m| { + // _ = win.printSegment(.{ .text = str }, .{ .col_offset = 1, .row_offset = 1 }); - if (m.type == .press) { - // const txt = try std.fmt.allocPrint(gpa, "col={} row={} xo={} yo={}", .{ m.col, m.row, m.xoffset, m.yoffset }); - // constlen = 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 => {}, - } + // if (m.type == .press) {} + // }, + // .winsize => |ws| try vx.resize(gpa, tty.writer(), ws), + // else => {}, + // } - try vx.render(tty.writer()); - } + // try vx.render(tty.writer()); + // } } |
