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