╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
172 // all repo tabs share the .repo parent, so this stays on the page 173 // rather than navigating. 174 if (header.getSelectedIndex()) |index| { 175 stack.getFocus().child_id = stack.children.keys()[index]; 176 switch (index) { 177 // files/commits carry this page's content route (directory / log 178 // page); settings/auth carry only "owner/name". 179 1 => self.session.data.current_page = .{ .repo_commits = .{ .name = self.data.commits_route_name } }, 180 2 => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 181 3 => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 182 // the quit tab is tty-only and not a route, so leave current_page 183 // alone (nothing to mirror into the url). 184 4 => {}, 185 else => self.session.data.current_page = .{ .repo = self.data.route_name }, 186 } 187 } 188 try self.box.build(allocator, constraint, root_focus); 189 } 190 191 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 192 if (self.getFocus().child_id) |child_id| { 193 if (self.box.children.getIndex(child_id)) |current_index| { 194 const child = &self.box.children.values()[current_index].widget; 195 var index = current_index; 196 197 const Direction = enum { up, down, none }; 198 const direction: Direction = switch (key) { 199 .arrow_up => .up, 200 .arrow_down => .down, 201 .mouse => |mouse| if (mouse.action == .scroll) 202 (if (mouse.action.scroll == .up) .up else .down) 203 else 204 .none, 205 else => .none, 206 }; 207 208 switch (direction) { 209 .up => { 210 switch (child.*) { 211 .repo_header => { 212 try child.input(allocator, key, root_focus); 213 }, 214 .stack => { 215 if (child.stack.getSelected()) |selected_widget| { 216 const at_top = switch (selected_widget.*) { 217 .repo_files => |*v| v.getSelectedIndex() == 0, 218 .repo_commits => |*v| v.getSelectedIndex() == 0, 219 .home_settings => |*v| v.getSelectedIndex() == 0, 220 .home_auth => |*v| v.getSelectedIndex() == 0, 221 .quit => |*v| v.getSelectedIndex() == 0, 222 else => false, 223 }; 224 if (at_top) { 225 index = header_index; 226 } else { 227 try child.input(allocator, key, root_focus); 228 } 229 } 230 }, 231 else => {}, 232 } 233 }, 234 .down => { 235 switch (child.*) { 236 .repo_header => { 237 index = stack_index; 238 }, 239 .stack => { 240 try child.input(allocator, key, root_focus); 241 }, 242 else => {}, 243 } 244 }, 245 .none => { 246 try child.input(allocator, key, root_focus); 247 }, 248 } 249 250 if (index != current_index) { 251 try root_focus.setFocus(self.box.children.keys()[index]); 252 } 253 } 254 } 255 } 256 257 pub fn clearGrid(self: *View) void { 258 self.box.clearGrid(); 259 } 260 261 pub fn getGrid(self: View) ?Grid { 262 return self.box.getGrid(); 263 } 264 265 pub fn getFocus(self: *View) *Focus { 266 return self.box.getFocus(); 267 } 268 }; 269