an experimental irc client
1const std = @import("std");
2const app = @import("app.zig");
3const completer = @import("completer.zig");
4const vaxis = @import("vaxis");
5pub const irc = @import("irc.zig");
6pub const lua = @import("lua.zig");
7
8pub const App = app.App;
9pub const Completer = completer.Completer;
10pub const EventLoop = vaxis.Loop(Event);
11pub const WriteQueue = vaxis.Queue(WriteEvent, 64);
12
13pub const Bind = struct {
14 key: vaxis.Key,
15 command: Command,
16};
17
18pub const Command = union(enum) {
19 /// a raw irc command. Sent verbatim
20 quote,
21 join,
22 me,
23 msg,
24 @"next-channel",
25 @"prev-channel",
26 quit,
27 who,
28 names,
29 part,
30 close,
31 redraw,
32 lua_function: i32,
33
34 pub var user_commands: std.StringHashMap(i32) = undefined;
35
36 /// only contains void commands
37 const map = std.StaticStringMap(Command).initComptime(.{
38 .{ "quote", .quote },
39 .{ "join", .join },
40 .{ "me", .me },
41 .{ "msg", .msg },
42 .{ "next-channel", .@"next-channel" },
43 .{ "prev-channel", .@"prev-channel" },
44 .{ "quit", .quit },
45 .{ "who", .who },
46 .{ "names", .names },
47 .{ "part", .part },
48 .{ "close", .close },
49 .{ "redraw", .redraw },
50 });
51
52 pub fn fromString(str: []const u8) ?Command {
53 return map.get(str);
54 }
55
56 /// if we should append a space when completing
57 pub fn appendSpace(self: Command) bool {
58 return switch (self) {
59 .quote,
60 .join,
61 .me,
62 .msg,
63 .part,
64 .close,
65 => true,
66 else => false,
67 };
68 }
69};
70
71/// Any event our application will handle
72pub const Event = union(enum) {
73 key_press: vaxis.Key,
74 mouse: vaxis.Mouse,
75 winsize: vaxis.Winsize,
76 focus_out,
77 irc: IrcEvent,
78 connect: irc.Client.Config,
79 redraw,
80 paste_start,
81 paste_end,
82};
83
84pub const IrcEvent = struct {
85 client: *irc.Client,
86 msg: irc.Slice,
87};
88
89/// An event our write thread will handle
90pub const WriteEvent = union(enum) {
91 write: struct {
92 client: *irc.Client,
93 msg: []const u8,
94 allocator: std.mem.Allocator,
95 },
96 join,
97};