an experimental irc client
at main 2.8 kB view raw
1const std = @import("std"); 2const options = @import("build_options"); 3const builtin = @import("builtin"); 4const comlink = @import("comlink.zig"); 5const vaxis = @import("vaxis"); 6const ziglua = @import("ziglua"); 7 8const Lua = ziglua.Lua; 9 10const log = std.log.scoped(.main); 11 12pub const panic = vaxis.panic_handler; 13 14pub const version = options.version; 15 16/// Called after receiving a terminating signal 17fn cleanUp(sig: c_int) callconv(.C) void { 18 if (vaxis.tty.global_tty) |gty| { 19 const reset: []const u8 = vaxis.ctlseqs.csi_u_pop ++ 20 vaxis.ctlseqs.mouse_reset ++ 21 vaxis.ctlseqs.bp_reset ++ 22 vaxis.ctlseqs.rmcup; 23 24 gty.anyWriter().writeAll(reset) catch {}; 25 26 gty.deinit(); 27 } 28 if (sig < 255 and sig >= 0) 29 std.process.exit(@as(u8, @intCast(sig))) 30 else 31 std.process.exit(1); 32} 33 34pub fn main() !void { 35 var debug_allocator: std.heap.DebugAllocator(.{}) = .init; 36 const gpa, const is_debug = gpa: { 37 break :gpa switch (builtin.mode) { 38 .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, 39 .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, 40 }; 41 }; 42 defer if (is_debug) { 43 _ = debug_allocator.deinit(); 44 }; 45 46 var args = try std.process.argsWithAllocator(gpa); 47 while (args.next()) |arg| { 48 if (argMatch("-v", "--version", arg)) { 49 const stdout = std.io.getStdOut(); 50 try stdout.writer().print("comlink {s}\n", .{version}); 51 return; 52 } 53 } 54 55 // Handle termination signals 56 switch (builtin.os.tag) { 57 .windows => {}, 58 else => { 59 var action: std.posix.Sigaction = .{ 60 .handler = .{ .handler = cleanUp }, 61 .mask = switch (builtin.os.tag) { 62 .macos => 0, 63 else => std.posix.empty_sigset, 64 }, 65 .flags = 0, 66 }; 67 std.posix.sigaction(std.posix.SIG.INT, &action, null); 68 std.posix.sigaction(std.posix.SIG.TERM, &action, null); 69 }, 70 } 71 72 comlink.Command.user_commands = std.StringHashMap(i32).init(gpa); 73 defer comlink.Command.user_commands.deinit(); 74 75 var app = try vaxis.vxfw.App.init(gpa); 76 defer app.deinit(); 77 78 var comlink_app: comlink.App = undefined; 79 try comlink_app.init(gpa, &app.vx.unicode); 80 defer comlink_app.deinit(); 81 82 try app.run(comlink_app.widget(), .{}); 83} 84 85fn argMatch(maybe_short: ?[]const u8, maybe_long: ?[]const u8, arg: [:0]const u8) bool { 86 if (maybe_short) |short| { 87 if (std.mem.eql(u8, short, arg)) return true; 88 } 89 if (maybe_long) |long| { 90 if (std.mem.eql(u8, long, arg)) return true; 91 } 92 return false; 93} 94 95test { 96 _ = @import("format.zig"); 97 _ = @import("irc.zig"); 98}