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, 256);
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 query,
25 @"next-channel",
26 @"prev-channel",
27 quit,
28 who,
29 names,
30 part,
31 close,
32 redraw,
33 version,
34 lua_function: i32,
35
36 pub var user_commands: std.StringHashMap(i32) = undefined;
37
38 /// only contains void commands
39 const map = std.StaticStringMap(Command).initComptime(.{
40 .{ "quote", .quote },
41 .{ "join", .join },
42 .{ "me", .me },
43 .{ "msg", .msg },
44 .{ "query", .query },
45 .{ "next-channel", .@"next-channel" },
46 .{ "prev-channel", .@"prev-channel" },
47 .{ "quit", .quit },
48 .{ "who", .who },
49 .{ "names", .names },
50 .{ "part", .part },
51 .{ "close", .close },
52 .{ "redraw", .redraw },
53 .{ "version", .version },
54 });
55
56 pub fn fromString(str: []const u8) ?Command {
57 return map.get(str);
58 }
59
60 /// if we should append a space when completing
61 pub fn appendSpace(self: Command) bool {
62 return switch (self) {
63 .quote,
64 .join,
65 .me,
66 .msg,
67 .part,
68 .close,
69 => true,
70 else => false,
71 };
72 }
73};
74
75/// Any event our application will handle
76pub const Event = union(enum) {
77 key_press: vaxis.Key,
78 mouse: vaxis.Mouse,
79 winsize: vaxis.Winsize,
80 focus_out,
81 irc: IrcEvent,
82 connect: irc.Client.Config,
83 redraw,
84 paste_start,
85 paste_end,
86};
87
88pub const IrcEvent = struct {
89 client: *irc.Client,
90 msg: irc.Slice,
91};
92
93/// An event our write thread will handle
94pub const WriteEvent = union(enum) {
95 write: struct {
96 client: *irc.Client,
97 msg: []const u8,
98 },
99 join,
100};