~rockorager/comlink

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v3] ui: set window title to current channel

Details
Message ID
<20240716214015.76218-1-greg@gpanders.com>
DKIM signature
pass
Download raw message
Patch: +15 -2
The IRC specification does not mention an explicit channel name length
[1], but I found that Libera.Chat does enforce a length of around 48
characters. So the 64 byte buffer should be plenty in most cases, but
just in case we truncate the channel name (and drop the " - comlink"
suffix) if the channel name is too long.

[1]: https://modern.ircdocs.horse/#channels
---
v3:
  - Forgot to include the link to the spec

 src/App.zig | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/App.zig b/src/App.zig
index 7e7e0c1..84eae8c 100644
--- a/src/App.zig
+++ b/src/App.zig
@@ -1532,7 +1532,9 @@ fn draw(self: *App) !void {
                    self.loop.?.postEvent(.redraw);
                }
            }
            var chan_style: vaxis.Style = if (row == self.state.buffers.selected_idx)

            const is_current = row == self.state.buffers.selected_idx;
            var chan_style: vaxis.Style = if (is_current)
                .{
                    .fg = if (client.status == .disconnected) .{ .index = 8 } else .default,
                    .reverse = true,
@@ -1590,7 +1592,7 @@ fn draw(self: *App) !void {
                        .style = chan_style,
                    },
                );
            if (row == self.state.buffers.selected_idx) {
            if (is_current) {
                var write_buf: [128]u8 = undefined;
                if (channel.has_unread) {
                    channel.has_unread = false;
@@ -1618,6 +1620,17 @@ fn draw(self: *App) !void {
                };
                _ = try topic_win.print(&topic_seg, .{ .wrap = .none });

                {
                    var buf: [64]u8 = undefined;
                    const title = std.fmt.bufPrint(&buf, "{s} - comlink", .{channel.name}) catch title: {
                        // If the channel name is too long to fit in our buffer just truncate
                        const len = @min(buf.len, channel.name.len);
                        @memcpy(buf[0..len], channel.name[0..len]);
                        break :title buf[0..len];
                    };
                    try self.vx.setTitle(self.tty.anyWriter(), title);
                }

                if (hasMouse(member_list_win, self.state.mouse)) |mouse| {
                    switch (mouse.button) {
                        .wheel_up => {
-- 
2.45.2
Details
Message ID
<D2S2MB7Z7GFX.3JJ5VX3S39EBJ@timculverhouse.com>
In-Reply-To
<20240716214015.76218-1-greg@gpanders.com> (view parent)
DKIM signature
pass
Download raw message
On Tue Jul 16, 2024 at 4:40 PM CDT, Gregory Anders wrote:
> The IRC specification does not mention an explicit channel name length
> [1], but I found that Libera.Chat does enforce a length of around 48
> characters. So the 64 byte buffer should be plenty in most cases, but
> just in case we truncate the channel name (and drop the " - comlink"
> suffix) if the channel name is too long.
>
> [1]: https://modern.ircdocs.horse/#channels
> ---

Applied! Thanks!
Reply to thread Export thread (mbox)