summaryrefslogtreecommitdiff
path: root/src/shock.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/shock.zig')
-rw-r--r--src/shock.zig44
1 files changed, 29 insertions, 15 deletions
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});
}