~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

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

Details
Message ID
<20240716213522.75789-2-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.
---
I tested this by changing the buffer size to 32 bytes and joining
#somechannelwithareallyreallyreallyreallylongname and verified that the
channel name was correctly truncated in the window title.

v2:
  - Update commit message
  - Truncate channel name if it's too long

 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
Reply to thread Export thread (mbox)