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