╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
139 const files = try Files.init(.xit, .{}, arena, &fork_repo, io, arena.child_allocator, location, requested_ref, requested_value, files_path, files_line); 140 const commits = try Commits.init(.xit, .{}, arena, &fork_repo, io, arena.child_allocator, haxy_moment, location, requested_ref, requested_value, commits_content, commits_base_oid); 141 142 return .{ 143 .header = try Header.init(arena, target_record.event.name, owner.event.name, &id_hex, requested_value), 144 .files = files, 145 .commits = commits, 146 .patch = patch_data, 147 .settings = Settings.init(), 148 .auth = Auth.init(), 149 .quit = Quit.init(), 150 }; 151 } 152 153 pub const View = struct { 154 box: wgt.Box(ui.Widget), 155 156 const header_index: usize = 0; 157 const stack_index: usize = 1; 158 159 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 160 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 161 errdefer box.deinit(allocator); 162 { 163 var header = try Header.View.init(allocator, &data.header, session); 164 errdefer header.deinit(allocator); 165 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 166 } 167 { 168 var stack = try wgt.Stack(ui.Widget).init(allocator); 169 errdefer stack.deinit(allocator); 170 const selected = data.patch.selectedThread() orelse return error.NotFound; 171 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 172 errdefer patch_detail.deinit(allocator); 173 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 174 { 175 var files = try Files.View.init(allocator, &data.files, session); 176 errdefer files.deinit(allocator); 177 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 178 } 179 { 180 var commits = try Commits.View.init(allocator, &data.commits, session); 181 errdefer commits.deinit(allocator); 182 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 183 } 184 if (session.data.user_id != null) { 185 var settings = try Settings.View.init(allocator, session); 186 errdefer settings.deinit(allocator); 187 try stack.children.put(allocator, settings.getFocus().id, .{ .home_settings = settings }); 188 } 189 if (!session.data.is_local) { 190 var auth = try Auth.View.init(allocator, &data.auth, session); 191 errdefer auth.deinit(allocator); 192 try stack.children.put(allocator, auth.getFocus().id, .{ .home_auth = auth }); 193 } 194 if (session.is_terminal) { 195 var quit = try Quit.View.init(allocator, session); 196 errdefer quit.deinit(allocator); 197 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 198 } 199 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 200 } 201 box.getFocus().child_id = box.children.keys()[header_index]; 202 return .{ .box = box }; 203 } 204 205 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 206 self.box.deinit(allocator); 207 } 208 209 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 210 self.clearGrid(); 211 const header = &self.box.children.values()[header_index].widget.fork_header; 212 const stack = &self.box.children.values()[stack_index].widget.stack; 213 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 214 try self.box.build(allocator, constraint, root_focus); 215 } 216 217 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 218 const stack = &self.box.children.values()[stack_index].widget.stack; 219 const current_id = self.box.getFocus().child_id orelse return; 220 const current_index = self.box.children.getIndex(current_id) orelse return; 221 const child = &self.box.children.values()[current_index].widget; 222 var next_index = current_index; 223 switch (inp.vertDirection(key)) { 224 .up => switch (child.*) { 225 .fork_header => try child.input(allocator, key, root_focus), 226 .stack => if (stack.getSelected()) |selected| { 227 const at_top = switch (selected.*) { 228 .repo_patch_detail => |*view| view.atTop(root_focus), 229 .repo_files => |*view| view.getSelectedIndex() == 0, 230 .repo_commits => |*view| view.getSelectedIndex() == 0, 231 .home_settings => |*view| view.getSelectedIndex() == 0, 232 .home_auth => |*view| view.getSelectedIndex() == 0, 233 .quit => |*view| view.getSelectedIndex() == 0, 234 else => false, 235 }; 236 if (at_top) next_index = header_index else try child.input(allocator, key, root_focus); 237 }, 238 else => {}, 239 }, 240 .down => switch (child.*) { 241 .fork_header => { 242 if (stack.getSelected()) |selected| switch (selected.*) { 243 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 244 .repo_files => |*view| if (view.focusCloneUrl(root_focus)) return, 245 .repo_commits => |*view| if (view.focusCloneUrl(root_focus)) return, 246 else => {}, 247 }; 248 next_index = stack_index; 249 }, 250 .stack => try child.input(allocator, key, root_focus), 251 else => {}, 252 }, 253 .none => try child.input(allocator, key, root_focus), 254 } 255 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 256 } 257 258 pub fn clearGrid(self: *View) void { 259 self.box.clearGrid(); 260 } 261 262 pub fn getGrid(self: View) ?Grid { 263 return self.box.getGrid(); 264 } 265 266 pub fn getFocus(self: *View) *Focus { 267 return self.box.getFocus(); 268 } 269 }; 270