also looking at this
Add Windows support and CI coverage
#24
6 files
+170
-266
| @@ -1,24 +1,30 @@ | ||
| 1 | 1 | const std = ; |
| 2 | const builtin = ; | |
| 2 | 3 | const lib = ; |
| 3 | 4 | const compat = lib.compat; |
| 4 | 5 | |
| 5 | 6 | // Global signal handler state |
| 6 | 7 | var shutdown_requested = std.atomic.Value(bool).init(false); |
| 7 | 8 | |
| 8 | /// Signal handler for SIGINT and SIGTERM | |
| 9 | fn handleSignal(sig: std.posix.SIG) callconv(.c) void { | |
| 10 | _ = sig; | |
| 11 | shutdown_requested.store(true, .monotonic); | |
| 12 | std.debug.print("\n\nShutdown requested... cleaning up\n", .{}); | |
| 13 | } | |
| 14 | ||
| 15 | 9 | /// Install signal handlers |
| 16 | 10 | fn installSignalHandlers() !void { |
| 11 | // Windows console control events retain their native default behavior: | |
| 12 | // Ctrl-C and console close terminate the CLI. POSIX platforms install | |
| 13 | // cooperative handlers so long-running watch/UI modes can clean up. | |
| 14 | if (comptime builtin.os.tag == .windows) return; | |
| 15 | ||
| 16 | const Handler = struct { | |
| 17 | fn handle(sig: std.posix.SIG) callconv(.c) void { | |
| 18 | _ = sig; | |
| 19 | shutdown_requested.store(true, .monotonic); | |
| 20 | std.debug.print("\n\nShutdown requested... cleaning up\n", .{}); | |
| 21 | } | |
| 22 | }; | |
| 17 | 23 | const posix = std.posix; |
| 18 | 24 | |
| 19 | 25 | // Install SIGINT handler (Ctrl+C) |
| 20 | 26 | const sigint_action = posix.Sigaction{ |
| 21 | .handler = .{ .handler = handleSignal }, | |
| 27 | .handler = .{ .handler = Handler.handle }, | |
| 22 | 28 | .mask = posix.sigemptyset(), |
| 23 | 29 | .flags = 0, |
| 24 | 30 | }; |
| @@ -26,7 +32,7 @@ fn installSignalHandlers() !void { | ||
| 26 | 32 | |
| 27 | 33 | // Install SIGTERM handler |
| 28 | 34 | const sigterm_action = posix.Sigaction{ |
| 29 | .handler = .{ .handler = handleSignal }, | |
| 35 | .handler = .{ .handler = Handler.handle }, | |
| 30 | 36 | .mask = posix.sigemptyset(), |
| 31 | 37 | .flags = 0, |
| 32 | 38 | }; |
| @@ -52,7 +58,8 @@ pub fn main(init: std.process.Init.Minimal) !void { | ||
| 52 | 58 | for (args_list.items) |arg| allocator.free(arg); |
| 53 | 59 | args_list.deinit(allocator); |
| 54 | 60 | } |
| 55 | var args_iter = std.process.Args.Iterator.init(init.args); | |
| 61 | var args_iter = try std.process.Args.Iterator.initAllocator(init.args, allocator); | |
| 62 | defer args_iter.deinit(); | |
| 56 | 63 | while (args_iter.next()) |arg| { |
| 57 | 64 | try args_list.append(allocator, try allocator.dupe(u8, arg)); |
| 58 | 65 | } |