╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Home.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
79 errdefer repos_view.deinit(allocator); 80 try stack.children.put(allocator, repos_view.getFocus().id, .{ .home_repos = repos_view }); 81 } 82 83 { 84 var settings_view = try Settings.View.init(allocator, &data.settings, session); 85 errdefer settings_view.deinit(allocator); 86 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 87 } 88 89 { 90 var auth_view = try Auth.View.init(allocator, &data.auth, session, users_tab_id); 91 errdefer auth_view.deinit(allocator); 92 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 93 } 94 95 if (session.is_terminal) { 96 var quit_view = try Quit.View.init(allocator, &data.quit, session); 97 errdefer quit_view.deinit(allocator); 98 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 99 } 100 101 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 102 } 103 104 var self = View{ 105 .box = box, 106 .data = data, 107 .session = session, 108 }; 109 self.getFocus().child_id = box.children.keys()[header_index]; 110 return self; 111 } 112 113 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 114 self.box.deinit(allocator); 115 } 116 117 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 118 self.clearGrid(); 119 const header = &self.box.children.values()[header_index].widget.home_header; 120 const stack = &self.box.children.values()[stack_index].widget.stack; 121 122 // each header tab maps 1:1 to a stack child by position; mirror the 123 // selected child's page into the url, keyed by its kind 124 if (header.getSelectedIndex()) |index| { 125 stack.getFocus().child_id = stack.children.keys()[index]; 126 switch (std.meta.activeTag(stack.children.values()[index])) { 127 // mirror each list tab's built pagination window so the url stays 128 // consistent with what's shown (and so a build doesn't reset it). 129 .home_users => self.session.data.current_page = .{ .home_users = self.data.users.after }, 130 .home_repos => self.session.data.current_page = .{ .home_repos = self.data.repos.after }, 131 .home_settings => self.session.data.current_page = .home_settings, 132 .home_auth => self.session.data.current_page = .home_auth, 133 // the quit tab is tty-only and not a route, so leave current_page 134 // alone (nothing to mirror into the url). 135 else => {}, 136 } 137 } 138 try self.box.build(allocator, constraint, root_focus); 139 } 140 141 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 142 if (self.getFocus().child_id) |child_id| { 143 if (self.box.children.getIndex(child_id)) |current_index| { 144 const child = &self.box.children.values()[current_index].widget; 145 var index = current_index; 146 147 const Direction = enum { up, down, none }; 148 const direction: Direction = switch (key) { 149 .arrow_up => .up, 150 .arrow_down => .down, 151 .mouse => |mouse| if (mouse.action == .scroll) 152 (if (mouse.action.scroll == .up) .up else .down) 153 else 154 .none, 155 else => .none, 156 }; 157 158 switch (direction) { 159 .up => { 160 switch (child.*) { 161 .home_header => { 162 try child.input(allocator, key, root_focus); 163 }, 164 .stack => { 165 if (child.stack.getSelected()) |selected_widget| { 166 const at_top = switch (selected_widget.*) { 167 .home_users => |*v| v.getSelectedIndex() == 0, 168 .home_repos => |*v| v.getSelectedIndex() == 0, 169 .home_settings => |*v| v.getSelectedIndex() == 0, 170 .home_auth => |*v| v.getSelectedIndex() == 0, 171 .quit => |*v| v.getSelectedIndex() == 0, 172 else => false, 173 }; 174 if (at_top) { 175 index = header_index; 176 } else { 177 try child.input(allocator, key, root_focus); 178 } 179 } 180 }, 181 else => {}, 182 } 183 }, 184 .down => { 185 switch (child.*) { 186 .home_header => { 187 index = stack_index; 188 }, 189 .stack => { 190 try child.input(allocator, key, root_focus); 191 }, 192 else => {}, 193 } 194 }, 195 .none => { 196 try child.input(allocator, key, root_focus); 197 }, 198 } 199 200 if (index != current_index) { 201 root_focus.setFocus(self.box.children.keys()[index]); 202 } 203 } 204 } 205 } 206 207 pub fn clearGrid(self: *View) void { 208 self.box.clearGrid(); 209 } 210 211 pub fn getGrid(self: View) ?Grid { 212 return self.box.getGrid(); 213 } 214 215 pub fn getFocus(self: *View) *Focus { 216 return self.box.getFocus(); 217 } 218 }; 219