╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Logout.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
87 88 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 89 const ansi_box = &self.center.child.box.children.values()[ansi_index].widget.box; 90 try ansi_box.children.values()[0].widget.text_box.setContent(allocator, ansiLabel(self.session)); 91 try self.center.build(allocator, constraint, root_focus); 92 } 93 94 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 95 _ = allocator; 96 const focused_id = if (self.atTop()) self.ansi_id else self.logout_id; 97 switch (key) { 98 .arrow_up => root_focus.setFocus(self.ansi_id), 99 .arrow_down => root_focus.setFocus(self.logout_id), 100 .enter => try self.activate(focused_id), 101 .mouse => |mouse| if (inp.leftClickOn(root_focus, focused_id, mouse)) try self.activate(focused_id), 102 else => {}, 103 } 104 } 105 106 fn activate(self: *View, button_id: usize) !void { 107 if (button_id == self.ansi_id) { 108 try self.session.push(.toggle_ansi); 109 return; 110 } 111 self.session.logOut(); 112 // leave the auth tab for the page it belongs to, where the web's 113 // /logout redirect also lands 114 try self.session.navigate(self.session.data.current_page.pageRoot()); 115 } 116 117 pub fn clearGrid(self: *View) void { 118 self.center.clearGrid(); 119 } 120 121 pub fn getGrid(self: View) ?Grid { 122 return self.center.getGrid(); 123 } 124 125 pub fn getFocus(self: *View) *Focus { 126 return self.center.getFocus(); 127 } 128 129 pub fn atTop(self: View) bool { 130 return self.center.child.box.focus.child_id == self.center.child.box.children.keys()[ansi_index]; 131 } 132 }; 133 134 fn ansiLabel(session: *const ui.Session) []const u8 { 135 return if (session.data.enable_ansi) "turn off ANSI art" else "turn on ANSI art"; 136 } 137