╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
175 176 // refs — the repo's branches and tags. 177 { 178 var refs_view = try Refs.View.init(allocator, &data.refs, session); 179 errdefer refs_view.deinit(allocator); 180 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 181 } 182 183 { 184 var settings_view = try Settings.View.init(allocator, &data.settings, session); 185 errdefer settings_view.deinit(allocator); 186 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 187 } 188 189 { 190 var auth_view = try Auth.View.init(allocator, &data.auth, session, files_tab_id); 191 errdefer auth_view.deinit(allocator); 192 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 193 } 194 195 if (session.is_terminal) { 196 var quit_view = try Quit.View.init(allocator, &data.quit, session); 197 errdefer quit_view.deinit(allocator); 198 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 199 } 200 201 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 202 } 203 204 var self = View{ .box = box, .data = data, .session = session }; 205 self.getFocus().child_id = box.children.keys()[header_index]; 206 return self; 207 } 208 209 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 210 self.box.deinit(allocator); 211 } 212 213 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 214 self.clearGrid(); 215 const header = &self.box.children.values()[header_index].widget.repo_header; 216 const stack = &self.box.children.values()[stack_index].widget.stack; 217 218 // each header tab maps 1:1 to a stack child by position. mirror the 219 // selection into current_page so the host can push the matching url; 220 // all repo tabs share the .repo parent, so this stays on the page 221 // rather than navigating. 222 if (header.getSelectedIndex()) |index| { 223 stack.getFocus().child_id = stack.children.keys()[index]; 224 switch (std.meta.activeTag(stack.children.values()[index])) { 225 // files/commits carry this page's content route (directory / log 226 // page); settings/auth carry only "owner/name". 227 .repo_commits => self.session.data.current_page = .{ .repo_commits = .{ .name = self.data.commits_route_name, .after = self.data.commits_after } }, 228 // the refs tab mirrors this page's paginated column + offset. 229 .repo_refs => self.session.data.current_page = .{ .repo_refs = .{ .name = self.data.identity, .kind = self.data.refs.kind, .after = self.data.refs.after } }, 230 .home_settings => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 231 .home_auth => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 232 // the quit tab is tty-only and not a route, so leave current_page 233 // alone (nothing to mirror into the url). 234 .quit => {}, 235 // the files tab (this page's directory route) 236 else => self.session.data.current_page = .{ .repo = self.data.route_name }, 237 } 238 } 239 try self.box.build(allocator, constraint, root_focus); 240 } 241 242 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 243 if (self.getFocus().child_id) |child_id| { 244 if (self.box.children.getIndex(child_id)) |current_index| { 245 const child = &self.box.children.values()[current_index].widget; 246 var index = current_index; 247 248 const Direction = enum { up, down, none }; 249 const direction: Direction = switch (key) { 250 .arrow_up => .up, 251 .arrow_down => .down, 252 .mouse => |mouse| if (mouse.action == .scroll) 253 (if (mouse.action.scroll == .up) .up else .down) 254 else 255 .none, 256 else => .none, 257 }; 258 259 switch (direction) { 260 .up => { 261 switch (child.*) { 262 .repo_header => { 263 try child.input(allocator, key, root_focus); 264 }, 265 .stack => { 266 if (child.stack.getSelected()) |selected_widget| { 267 const at_top = switch (selected_widget.*) { 268 .repo_files => |*v| v.getSelectedIndex() == 0, 269 .repo_commits => |*v| v.getSelectedIndex() == 0, 270 .repo_refs => |*v| v.getSelectedIndex() == 0, 271 .home_settings => |*v| v.getSelectedIndex() == 0, 272 .home_auth => |*v| v.getSelectedIndex() == 0, 273 .quit => |*v| v.getSelectedIndex() == 0, 274 else => false, 275 }; 276 if (at_top) { 277 index = header_index; 278 } else { 279 try child.input(allocator, key, root_focus); 280 } 281 } 282 }, 283 else => {}, 284 } 285 }, 286 .down => { 287 switch (child.*) { 288 .repo_header => { 289 index = stack_index; 290 }, 291 .stack => { 292 try child.input(allocator, key, root_focus); 293 }, 294 else => {}, 295 } 296 }, 297 .none => { 298 try child.input(allocator, key, root_focus); 299 }, 300 } 301 302 if (index != current_index) { 303 try root_focus.setFocus(self.box.children.keys()[index]); 304 } 305 } 306 } 307 } 308 309 pub fn clearGrid(self: *View) void { 310 self.box.clearGrid(); 311 } 312 313 pub fn getGrid(self: View) ?Grid { 314 return self.box.getGrid(); 315 } 316 317 pub fn getFocus(self: *View) *Focus { 318 return self.box.getFocus(); 319 } 320 }; 321