an experimental irc client

Add query command and opening buffer by name

authored by

Palanix and committed by rockorager.dev cc5cf1b1 2993fd2b

+58
+56
src/app.zig
··· 810 810 } 811 811 } 812 812 813 + pub fn selectChannelName(self: *App, cl: *irc.Client, name: []const u8) void { 814 + var i: usize = 0; 815 + for (self.clients.items) |client| { 816 + i += 1; 817 + for (client.channels.items) |*channel| { 818 + if (cl == client) { 819 + if (std.mem.eql(u8, name, channel.name)) { 820 + self.state.buffers.selected_idx = i; 821 + } 822 + } 823 + i += 1; 824 + } 825 + } 826 + } 827 + 813 828 /// handle a command 814 829 pub fn handleCommand(self: *App, lua_state: *Lua, buffer: irc.Buffer, cmd: []const u8) !void { 815 830 const command: comlink.Command = blk: { ··· 878 893 }, 879 894 ); 880 895 return client.queueWrite(msg); 896 + }, 897 + .query => { 898 + const s = std.mem.indexOfScalar(u8, cmd, ' ') orelse return error.InvalidCommand; 899 + const e = std.mem.indexOfScalarPos(u8, cmd, s + 1, ' ') orelse cmd.len; 900 + 901 + const ch = try client.getOrCreateChannel(cmd[s + 1 .. e]); 902 + try client.requestHistory(.after, ch); 903 + self.selectChannelName(client, ch.name); 904 + //handle sending the message 905 + if (cmd.len - e + 1 > 0) { 906 + const msg = try std.fmt.bufPrint( 907 + &buf, 908 + "PRIVMSG {s} :{s}\r\n", 909 + .{ 910 + cmd[s + 1 .. e], 911 + cmd[e + 1 ..], 912 + }, 913 + ); 914 + return client.queueWrite(msg); 915 + } 881 916 }, 882 917 .names => { 883 918 if (channel == null) return error.InvalidCommand; ··· 1521 1556 } 1522 1557 1523 1558 fn drawBufferList(self: *App, clients: []*irc.Client, win: vaxis.Window) !void { 1559 + // Handle mouse 1560 + { 1561 + if (win.hasMouse(self.state.mouse)) |mouse| { 1562 + switch (mouse.button) { 1563 + .wheel_up => { 1564 + self.state.buffers.scroll_offset -|= 3; 1565 + self.state.mouse.?.button = .none; 1566 + }, 1567 + .wheel_down => { 1568 + self.state.buffers.scroll_offset +|= 3; 1569 + self.state.mouse.?.button = .none; 1570 + }, 1571 + else => {}, 1572 + } 1573 + } 1574 + 1575 + self.state.buffers.scroll_offset = @min( 1576 + self.state.buffers.scroll_offset, 1577 + self.state.buffers.count -| win.height, 1578 + ); 1579 + } 1524 1580 const buf_list_w = self.state.buffers.width; 1525 1581 var row: usize = 0; 1526 1582
+2
src/comlink.zig
··· 21 21 join, 22 22 me, 23 23 msg, 24 + query, 24 25 @"next-channel", 25 26 @"prev-channel", 26 27 quit, ··· 40 41 .{ "join", .join }, 41 42 .{ "me", .me }, 42 43 .{ "msg", .msg }, 44 + .{ "query", .query }, 43 45 .{ "next-channel", .@"next-channel" }, 44 46 .{ "prev-channel", .@"prev-channel" }, 45 47 .{ "quit", .quit },