╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ AuthTab.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
13 pub const View = struct { 14 text_box: wgt.TextBox, 15 session: *ui.Session, 16 17 pub fn init(allocator: std.mem.Allocator, session: *ui.Session) !View { 18 var text_box = try wgt.TextBox.init(allocator, login_tab_label, .{ .border_style = .single, .round_corners = true, .wrap_kind = .none }); 19 errdefer text_box.deinit(allocator); 20 text_box.getFocus().mode = .all; 21 text_box.getFocus().kind = .{ .custom = "ai:/auth" }; 22 return .{ 23 .text_box = text_box, 24 .session = session, 25 }; 26 } 27 28 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 29 self.text_box.deinit(allocator); 30 } 31 32 // the logged-in user's name, or the login label 33 fn text(self: *const View) []const u8 { 34 if (self.session.data.user_id == null) return login_tab_label; 35 return self.session.data.user_name orelse unreachable; 36 } 37 38 pub fn minWidth(self: *const View) usize { 39 return self.text().len + 2; 40 } 41 42 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 43 try self.text_box.setContent(allocator, self.text()); 44 try self.text_box.build(allocator, constraint, root_focus); 45 } 46 47 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 48 try self.text_box.input(allocator, key, root_focus); 49 } 50 51 pub fn clearGrid(self: *View) void { 52 self.text_box.clearGrid(); 53 } 54 55 pub fn getGrid(self: View) ?Grid { 56 return self.text_box.getGrid(); 57 } 58 59 pub fn getFocus(self: *View) *Focus { 60 return self.text_box.getFocus(); 61 } 62 }; 63