╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
137 var auth_view = try Auth.View.init(allocator, &data.auth, session, repos_tab_id); 138 errdefer auth_view.deinit(allocator); 139 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 140 } 141 142 if (session.is_terminal) { 143 var quit_view = try Quit.View.init(allocator, &data.quit, session); 144 errdefer quit_view.deinit(allocator); 145 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 146 } 147 148 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 149 } 150 151 var self = View{ .box = box, .data = data, .session = session }; 152 self.getFocus().child_id = box.children.keys()[header_index]; 153 return self; 154 } 155 156 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 157 self.box.deinit(allocator); 158 } 159 160 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 161 self.clearGrid(); 162 const header = &self.box.children.values()[header_index].widget.user_header; 163 const stack = &self.box.children.values()[stack_index].widget.stack; 164 165 // each header tab maps 1:1 to a stack child by position. mirror the 166 // selection into current_page so the host can push the matching url; 167 // all user tabs share the .user parent, so this stays on the page 168 // rather than navigating. 169 if (header.getSelectedIndex()) |index| { 170 stack.getFocus().child_id = stack.children.keys()[index]; 171 const name = self.data.route_name; 172 switch (std.meta.activeTag(stack.children.values()[index])) { 173 .home_settings => self.session.data.current_page = .{ .user_settings = name }, 174 .home_auth => self.session.data.current_page = .{ .user_auth = name }, 175 // the quit tab is tty-only and not a route, so leave current_page 176 // alone (nothing to mirror into the url). 177 .quit => {}, 178 // the repos list (the default tab) 179 else => self.session.data.current_page = .{ .user = name }, 180 } 181 } 182 try self.box.build(allocator, constraint, root_focus); 183 } 184 185 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 186 if (self.getFocus().child_id) |child_id| { 187 if (self.box.children.getIndex(child_id)) |current_index| { 188 const child = &self.box.children.values()[current_index].widget; 189 var index = current_index; 190 191 const Direction = enum { up, down, none }; 192 const direction: Direction = switch (key) { 193 .arrow_up => .up, 194 .arrow_down => .down, 195 .mouse => |mouse| if (mouse.action == .scroll) 196 (if (mouse.action.scroll == .up) .up else .down) 197 else 198 .none, 199 else => .none, 200 }; 201 202 switch (direction) { 203 .up => { 204 switch (child.*) { 205 .user_header => { 206 try child.input(allocator, key, root_focus); 207 }, 208 .stack => { 209 if (child.stack.getSelected()) |selected_widget| { 210 const at_top = switch (selected_widget.*) { 211 .flow_box_scroll => |*v| v.getSelectedIndex() == 0, 212 .home_settings => |*v| v.getSelectedIndex() == 0, 213 .home_auth => |*v| v.getSelectedIndex() == 0, 214 .quit => |*v| v.getSelectedIndex() == 0, 215 else => false, 216 }; 217 if (at_top) { 218 index = header_index; 219 } else { 220 try child.input(allocator, key, root_focus); 221 } 222 } 223 }, 224 else => {}, 225 } 226 }, 227 .down => { 228 switch (child.*) { 229 .user_header => { 230 index = stack_index; 231 }, 232 .stack => { 233 try child.input(allocator, key, root_focus); 234 }, 235 else => {}, 236 } 237 }, 238 .none => { 239 try child.input(allocator, key, root_focus); 240 }, 241 } 242 243 if (index != current_index) { 244 try root_focus.setFocus(self.box.children.keys()[index]); 245 } 246 } 247 } 248 } 249 250 pub fn clearGrid(self: *View) void { 251 self.box.clearGrid(); 252 } 253 254 pub fn getGrid(self: View) ?Grid { 255 return self.box.getGrid(); 256 } 257 258 pub fn getFocus(self: *View) *Focus { 259 return self.box.getFocus(); 260 } 261 }; 262