╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
130 var settings_view = try Settings.View.init(allocator, &data.settings, session); 131 errdefer settings_view.deinit(allocator); 132 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 133 } 134 135 { 136 var auth_view = try Auth.View.init(allocator, &data.auth, session, files_tab_id); 137 errdefer auth_view.deinit(allocator); 138 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 139 } 140 141 if (session.is_terminal) { 142 var quit_view = try Quit.View.init(allocator, &data.quit, session); 143 errdefer quit_view.deinit(allocator); 144 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 145 } 146 147 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 148 } 149 150 var self = View{ .box = box, .data = data, .session = session }; 151 self.getFocus().child_id = box.children.keys()[header_index]; 152 return self; 153 } 154 155 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 156 self.box.deinit(allocator); 157 } 158 159 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 160 self.clearGrid(); 161 const header = &self.box.children.values()[header_index].widget.repo_header; 162 const stack = &self.box.children.values()[stack_index].widget.stack; 163 164 // each header tab maps 1:1 to a stack child by position. mirror the 165 // selection into current_page so the host can push the matching url; 166 // all repo tabs share the .repo parent, so this stays on the page 167 // rather than navigating. 168 if (header.getSelectedIndex()) |index| { 169 stack.getFocus().child_id = stack.children.keys()[index]; 170 switch (index) { 171 // files/commits carry this page's content route (directory / log 172 // page); settings/auth carry only "owner/name". 173 1 => self.session.data.current_page = .{ .repo_commits = self.data.commits_route_name }, 174 2 => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 175 3 => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 176 // the quit tab is tty-only and not a route, so leave current_page 177 // alone (nothing to mirror into the url). 178 4 => {}, 179 else => self.session.data.current_page = .{ .repo = self.data.route_name }, 180 } 181 } 182 try self.box.build(allocator, constraint, root_focus); 183 } 184 185 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 186 if (self.getFocus().child_id) |child_id| { 187 if (self.box.children.getIndex(child_id)) |current_index| { 188 const child = &self.box.children.values()[current_index].widget; 189 var index = current_index; 190 191 const Direction = enum { up, down, none }; 192 const direction: Direction = switch (key) { 193 .arrow_up => .up, 194 .arrow_down => .down, 195 .mouse => |mouse| if (mouse.action == .scroll) 196 (if (mouse.action.scroll == .up) .up else .down) 197 else 198 .none, 199 else => .none, 200 }; 201 202 switch (direction) { 203 .up => { 204 switch (child.*) { 205 .repo_header => { 206 try child.input(allocator, key, root_focus); 207 }, 208 .stack => { 209 if (child.stack.getSelected()) |selected_widget| { 210 const at_top = switch (selected_widget.*) { 211 .repo_files => |*v| v.getSelectedIndex() == 0, 212 .repo_commits => |*v| v.getSelectedIndex() == 0, 213 .home_settings => |*v| v.getSelectedIndex() == 0, 214 .home_auth => |*v| v.getSelectedIndex() == 0, 215 .quit => |*v| v.getSelectedIndex() == 0, 216 else => false, 217 }; 218 if (at_top) { 219 index = header_index; 220 } else { 221 try child.input(allocator, key, root_focus); 222 } 223 } 224 }, 225 else => {}, 226 } 227 }, 228 .down => { 229 switch (child.*) { 230 .repo_header => { 231 index = stack_index; 232 }, 233 .stack => { 234 try child.input(allocator, key, root_focus); 235 }, 236 else => {}, 237 } 238 }, 239 .none => { 240 try child.input(allocator, key, root_focus); 241 }, 242 } 243 244 if (index != current_index) { 245 try root_focus.setFocus(self.box.children.keys()[index]); 246 } 247 } 248 } 249 } 250 251 pub fn clearGrid(self: *View) void { 252 self.box.clearGrid(); 253 } 254 255 pub fn getGrid(self: View) ?Grid { 256 return self.box.getGrid(); 257 } 258 259 pub fn getFocus(self: *View) *Focus { 260 return self.box.getFocus(); 261 } 262 }; 263