an experimental irc client

ui: handle /quit properly

+12 -23
+4 -23
src/app.zig
··· 59 59 60 60 completer: ?Completer, 61 61 62 - should_quit: bool, 63 - 64 62 binds: std.ArrayList(Bind), 65 63 66 64 paste_buffer: std.ArrayList(u8), ··· 104 102 .bundle = .{}, 105 103 .deinited = false, 106 104 .completer = null, 107 - .should_quit = false, 108 105 .buffer_list = .{ 109 106 .children = .{ 110 107 .builder = .{ ··· 207 204 for (self.binds.items) |bind| { 208 205 if (key.matches(bind.key.codepoint, bind.key.mods)) { 209 206 switch (bind.command) { 210 - .quit => self.should_quit = true, 207 + .quit => ctx.quit = true, 211 208 .@"next-channel" => self.nextChannel(), 212 209 .@"prev-channel" => self.prevChannel(), 213 210 .redraw => try ctx.queueRefresh(), ··· 486 483 }, 487 484 .@"next-channel" => self.nextChannel(), 488 485 .@"prev-channel" => self.prevChannel(), 489 - .quit => self.should_quit = true, 486 + .quit => { 487 + if (self.ctx) |ctx| ctx.quit = true; 488 + }, 490 489 .who => { 491 490 if (channel == null) return error.InvalidCommand; 492 491 const msg = try std.fmt.bufPrint( ··· 630 629 } 631 630 } 632 631 } 633 - 634 - /// Returns the number of lines the segments would consume in the given window 635 - fn lineCountForWindow(win: vaxis.Window, segments: []const vaxis.Segment) usize { 636 - // Fastpath if we have fewer bytes than the width 637 - var byte_count: usize = 0; 638 - for (segments) |segment| { 639 - byte_count += segment.text.len; 640 - } 641 - // One line if we are fewer bytes than the width 642 - if (byte_count <= win.width) return 1; 643 - 644 - // Slow path. We have to layout the text 645 - const result = win.print(segments, .{ .commit = false, .wrap = .word }) catch return 0; 646 - if (result.col == 0) 647 - return result.row 648 - else 649 - return result.row + 1; 650 - }
+8
src/ui.zig
··· 1 + const std = @import("std"); 2 + const vaxis = @import("vaxis"); 3 + 4 + const vxfw = vaxis.vxfw; 5 + 6 + const Allocator = std.mem.Allocator; 7 + 8 + pub const main = struct {};