╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
199 try stack.children.put(allocator, auth.getFocus().id, .{ .home_auth = auth }); 200 } 201 if (session.is_terminal) { 202 var quit = try Quit.View.init(allocator, session); 203 errdefer quit.deinit(allocator); 204 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 205 } 206 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 207 } 208 box.getFocus().child_id = box.children.keys()[header_index]; 209 return .{ .box = box }; 210 } 211 212 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 213 self.box.deinit(allocator); 214 } 215 216 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 217 self.clearGrid(); 218 const header = &self.box.children.values()[header_index].widget.fork_header; 219 const stack = &self.box.children.values()[stack_index].widget.stack; 220 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 221 try self.box.build(allocator, constraint, root_focus); 222 } 223 224 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 225 const stack = &self.box.children.values()[stack_index].widget.stack; 226 const current_id = self.box.getFocus().child_id orelse return; 227 const current_index = self.box.children.getIndex(current_id) orelse return; 228 const child = &self.box.children.values()[current_index].widget; 229 var next_index = current_index; 230 switch (inp.vertDirection(key)) { 231 .up => switch (child.*) { 232 .fork_header => try child.input(allocator, key, root_focus), 233 .stack => if (stack.getSelected()) |selected| { 234 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 235 }, 236 else => {}, 237 }, 238 .down => switch (child.*) { 239 .fork_header => { 240 if (stack.getSelected()) |selected| switch (selected.*) { 241 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 242 .repo_files => |*view| if (view.focusCloneUrl(root_focus)) return, 243 .repo_commits => |*view| if (view.focusCloneUrl(root_focus)) return, 244 else => {}, 245 }; 246 next_index = stack_index; 247 }, 248 .stack => try child.input(allocator, key, root_focus), 249 else => {}, 250 }, 251 .none => try child.input(allocator, key, root_focus), 252 } 253 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 254 } 255 256 pub fn clearGrid(self: *View) void { 257 self.box.clearGrid(); 258 } 259 260 pub fn getGrid(self: View) ?Grid { 261 return self.box.getGrid(); 262 } 263 264 pub fn getFocus(self: *View) *Focus { 265 return self.box.getFocus(); 266 } 267 }; 268