╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ AuthTab.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
22 errdefer text_box.deinit(allocator); 23 text_box.getFocus().mode = .all; 24 text_box.getFocus().kind = .{ .custom = "ai:/auth" }; 25 return .{ 26 .text_box = text_box, 27 .session = session, 28 .bottom_label_buf = undefined, 29 }; 30 } 31 32 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 33 self.text_box.deinit(allocator); 34 } 35 36 fn text(self: *const View) []const u8 { 37 return if (self.session.data.user_id == null) login_tab_label else logout_tab_label; 38 } 39 40 fn bottomLabel(self: *View) []const u8 { 41 if (self.session.data.user_id == null) return ""; 42 const name = self.session.data.user_name orelse return ""; 43 return ui.clippedBottomLabel(&self.bottom_label_buf, name) catch unreachable; 44 } 45 46 pub fn minWidth(self: *View) usize { 47 return @max(self.text().len, self.bottomLabel().len) + 2; 48 } 49 50 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 51 try self.text_box.setContent(allocator, self.text()); 52 self.text_box.options.bottom_label = self.bottomLabel(); 53 try self.text_box.build(allocator, constraint, root_focus); 54 } 55 56 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 57 try self.text_box.input(allocator, key, root_focus); 58 } 59 60 pub fn clearGrid(self: *View) void { 61 self.text_box.clearGrid(); 62 } 63 64 pub fn getGrid(self: View) ?Grid { 65 return self.text_box.getGrid(); 66 } 67 68 pub fn getFocus(self: *View) *Focus { 69 return self.text_box.getFocus(); 70 } 71 }; 72