From 4c12cb8aa39035c6ece5efad0971c6de4c2898fe Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Mar 2026 17:09:09 -0300 Subject: some changes to build.zig --- src/shock.zig | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/shock.zig b/src/shock.zig index 262b176..90e6edf 100644 --- a/src/shock.zig +++ b/src/shock.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const elfo = @import("elfo.zig"); pub fn main(init: std.process.Init.Minimal) !void { var args = init.args.iterate(); @@ -10,21 +11,21 @@ pub fn main(init: std.process.Init.Minimal) !void { var debug_alloc: std.heap.DebugAllocator(.{}) = .init; const alloc = debug_alloc.allocator(); - // var threaded: std.Io.Threaded = .init(alloc, .{ - // .argv0 = .init(init.args), - // .environ = init.environ, - // }); - // defer threaded.deinit(); - // const io = threaded.io(); - - var evented: std.Io.Evented = undefined; - try evented.init(alloc, .{ + var threaded: std.Io.Threaded = .init(alloc, .{ .argv0 = .init(init.args), .environ = init.environ, - .backing_allocator_needs_mutex = false, }); - defer evented.deinit(); - const io = evented.io(); + defer threaded.deinit(); + const io = threaded.io(); + + // var evented: std.Io.Evented = undefined; + // try evented.init(alloc, .{ + // .argv0 = .init(init.args), + // .environ = init.environ, + // .backing_allocator_needs_mutex = false, + // }); + // defer evented.deinit(); + // const io = evented.io(); // const f = try std.Io.Dir.cwd().openFile(io, subject, .{ .mode = .read_only }); // std.debug.print("file: {any}\n", .{f}); @@ -36,10 +37,23 @@ pub fn main(init: std.process.Init.Minimal) !void { const buf = try alloc.alloc(u8, 0x400); defer alloc.free(buf); - _ = try child.stdout.?.readPositionalAll(io, buf, 0); + _ = try child.stdout.?.readStreaming(io, &.{buf}); std.debug.print("spawned child: {any}\n", .{child}); - const term = try child.wait(io); - std.debug.print("waited term: {any}\n", .{term}); + // io.async(function: anytype, args: (unknown type)) + var child_fut = io.async(std.process.Child.wait, .{ &child, io }); + const child_out = try child_fut.await(io); + // const child_out = try child.wait(io); + std.debug.print("stdout: {s}\n", .{buf}); + + { + var buffer: [64]u8 = undefined; + const stderr = try io.lockStderr(&buffer, .escape_codes); + defer io.unlockStderr(); + const term = stderr.terminal(); + try elfo.printHexdump(u8, term.writer, term, buf, 0); + } + + std.debug.print("waited term: {any}\n", .{child_out}); } -- cgit v1.3