╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
96 try stack.children.put(allocator, files_view.getFocus().id, .{ .repo_files = files_view }); 97 } 98 99 { 100 var settings_view = try Settings.View.init(allocator, &data.settings, session); 101 errdefer settings_view.deinit(allocator); 102 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 103 } 104 105 { 106 var auth_view = try Auth.View.init(allocator, &data.auth, session, files_tab_id); 107 errdefer auth_view.deinit(allocator); 108 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 109 } 110 111 if (session.is_terminal) { 112 var quit_view = try Quit.View.init(allocator, &data.quit, session); 113 errdefer quit_view.deinit(allocator); 114 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 115 } 116 117 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 118 } 119 120 var self = View{ .box = box, .data = data, .session = session }; 121 self.getFocus().child_id = box.children.keys()[header_index]; 122 return self; 123 } 124 125 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 126 self.box.deinit(allocator); 127 } 128 129 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 130 self.clearGrid(); 131 const header = &self.box.children.values()[header_index].widget.repo_header; 132 const stack = &self.box.children.values()[stack_index].widget.stack; 133 134 // each header tab maps 1:1 to a stack child by position. mirror the 135 // selection into current_page so the host can push the matching url; 136 // all repo tabs share the .repo parent, so this stays on the page 137 // rather than navigating. 138 if (header.getSelectedIndex()) |index| { 139 stack.getFocus().child_id = stack.children.keys()[index]; 140 switch (index) { 141 // settings/auth carry only "owner/name"; files carries this 142 // page's directory (route_name) so the url keeps the dir. 143 1 => self.session.data.current_page = .{ .repo_settings = self.data.identity }, 144 2 => self.session.data.current_page = .{ .repo_auth = self.data.identity }, 145 // the quit tab is tty-only and not a route, so leave current_page 146 // alone (nothing to mirror into the url). 147 3 => {}, 148 else => self.session.data.current_page = .{ .repo = self.data.route_name }, 149 } 150 } 151 try self.box.build(allocator, constraint, root_focus); 152 } 153 154 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 155 if (self.getFocus().child_id) |child_id| { 156 if (self.box.children.getIndex(child_id)) |current_index| { 157 const child = &self.box.children.values()[current_index].widget; 158 var index = current_index; 159 160 const Direction = enum { up, down, none }; 161 const direction: Direction = switch (key) { 162 .arrow_up => .up, 163 .arrow_down => .down, 164 .mouse => |mouse| if (mouse.action == .scroll) 165 (if (mouse.action.scroll == .up) .up else .down) 166 else 167 .none, 168 else => .none, 169 }; 170 171 switch (direction) { 172 .up => { 173 switch (child.*) { 174 .repo_header => { 175 try child.input(allocator, key, root_focus); 176 }, 177 .stack => { 178 if (child.stack.getSelected()) |selected_widget| { 179 const at_top = switch (selected_widget.*) { 180 .repo_files => |*v| v.getSelectedIndex() == 0, 181 .home_settings => |*v| v.getSelectedIndex() == 0, 182 .home_auth => |*v| v.getSelectedIndex() == 0, 183 .quit => |*v| v.getSelectedIndex() == 0, 184 else => false, 185 }; 186 if (at_top) { 187 index = header_index; 188 } else { 189 try child.input(allocator, key, root_focus); 190 } 191 } 192 }, 193 else => {}, 194 } 195 }, 196 .down => { 197 switch (child.*) { 198 .repo_header => { 199 index = stack_index; 200 }, 201 .stack => { 202 try child.input(allocator, key, root_focus); 203 }, 204 else => {}, 205 } 206 }, 207 .none => { 208 try child.input(allocator, key, root_focus); 209 }, 210 } 211 212 if (index != current_index) { 213 try root_focus.setFocus(self.box.children.keys()[index]); 214 } 215 } 216 } 217 } 218 219 pub fn clearGrid(self: *View) void { 220 self.box.clearGrid(); 221 } 222 223 pub fn getGrid(self: View) ?Grid { 224 return self.box.getGrid(); 225 } 226 227 pub fn getFocus(self: *View) *Focus { 228 return self.box.getFocus(); 229 } 230 }; 231