an experimental irc client
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
34var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
35
36pub fn main() !void {
37 const gpa, const is_debug = gpa: {
38 break :gpa switch (builtin.mode) {
39 .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true },
40 .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false },
41 };
42 };
43 defer if (is_debug) {
44 _ = debug_allocator.deinit();
45 };
46
47 var args = try std.process.argsWithAllocator(gpa);
48 while (args.next()) |arg| {
49 if (argMatch("-v", "--version", arg)) {
50 const stdout = std.io.getStdOut();
51 try stdout.writer().print("comlink {s}\n", .{version});
52 return;
53 }
54 }
55
56 // Handle termination signals
57 switch (builtin.os.tag) {
58 .windows => {},
59 else => {
60 var action: std.posix.Sigaction = .{
61 .handler = .{ .handler = cleanUp },
62 .mask = switch (builtin.os.tag) {
63 .macos => 0,
64 else => std.posix.empty_sigset,
65 },
66 .flags = 0,
67 };
68 std.posix.sigaction(std.posix.SIG.INT, &action, null);
69 std.posix.sigaction(std.posix.SIG.TERM, &action, null);
70 },
71 }
72
73 comlink.Command.user_commands = std.StringHashMap(i32).init(gpa);
74 defer comlink.Command.user_commands.deinit();
75
76 var app = try vaxis.vxfw.App.init(gpa);
77 defer app.deinit();
78
79 var comlink_app: comlink.App = undefined;
80 try comlink_app.init(gpa, &app.vx.unicode);
81 defer comlink_app.deinit();
82
83 try app.run(comlink_app.widget(), .{});
84}
85
86fn argMatch(maybe_short: ?[]const u8, maybe_long: ?[]const u8, arg: [:0]const u8) bool {
87 if (maybe_short) |short| {
88 if (std.mem.eql(u8, short, arg)) return true;
89 }
90 if (maybe_long) |long| {
91 if (std.mem.eql(u8, long, arg)) return true;
92 }
93 return false;
94}
95
96test {
97 _ = @import("format.zig");
98 _ = @import("irc.zig");
99}