╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Delete.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
181 const failure = if (savedFeedback(self.session, self.target)) |saved| saved.failure else null; 182 self.textInput(confirm_index).options.top_label.text = if (failure == .wrong_confirm) self.mismatch_label else self.confirm_label; 183 self.textInput(password_index).options.top_label.text = if (failure == .wrong_password) " password (wrong) " else " password "; 184 // the web form handling finds the inputs by focus id 185 for ([_]usize{ confirm_index, password_index }) |index| { 186 try self.session.text_inputs.put(self.session.arena.allocator(), self.control_ids[index], self.textInput(index)); 187 } 188 // the window's height as a minimum centers a form that fits 189 try self.scroll.build(allocator, .{ 190 .min_size = .{ .width = constraint.min_size.width, .height = constraint.max_size.height orelse constraint.min_size.height }, 191 .max_size = constraint.max_size, 192 }, root_focus); 193 } 194 195 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 196 const focused = root_focus.grandchild_id orelse return; 197 const cur = std.mem.indexOfScalar(usize, &self.control_ids, focused) orelse return; 198 const submit_id = self.control_ids[submit_index]; 199 const on_submit = focused == submit_id; 200 const direction = inp.vertDirection(key); 201 const up = direction == .up or key == .back_tab; 202 if (up or direction == .down or key == .tab) { 203 // up from the first control is the sub header's, through `atTop` 204 if (up and cur == 0) return; 205 const next = if (up) cur - 1 else cur + 1; 206 if (next == self.control_ids.len) return; 207 root_focus.setFocus(self.control_ids[next]); 208 if (self.session.is_terminal) if (self.formBox().children.values()[next].rect) |rect| ui.widget.scrollToCenteredRect(&self.scroll, rect); 209 return; 210 } 211 switch (key) { 212 .enter => if (on_submit) return self.submitForm(allocator), 213 .mouse => |mouse| if (inp.leftClickOn(root_focus, submit_id, mouse)) return self.submitForm(allocator), 214 else => {}, 215 } 216 if (!on_submit) try self.textInput(cur).input(allocator, key, root_focus); 217 } 218 219 // delete the target. this is the terminal path; the web posts the form to 220 // the delete route 221 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 222 if (comptime wasm) return; 223 const io = self.session.io orelse return; 224 const users_dir = self.session.users_dir orelse return; 225 const admin_repo = self.session.admin_repo orelse return; 226 const user_id = self.session.userId() orelse return; 227 228 const confirm = try self.textInput(confirm_index).text(allocator); 229 defer allocator.free(confirm); 230 const password = try self.textInput(password_index).text(allocator); 231 defer allocator.free(password); 232 233 const failure = perform(io, allocator, users_dir, admin_repo, user_id, self.target, confirm, password) catch |err| switch (err) { 234 // only the main owner is offered the form 235 error.NotFound => return, 236 else => return err, 237 }; 238 if (failure) |value| { 239 self.session.data.form_feedback = .{ .delete = .{ .failure = value, .target = std.meta.activeTag(self.target), .confirm = try self.session.arena.allocator().dupe(u8, confirm) } }; 240 return; 241 } 242 243 switch (self.target) { 244 .repo, .fork => { 245 const name = self.session.data.user_name orelse unreachable; 246 try self.session.navigate(.{ .user_repos = .{ .name = ui.RoutablePage.Array(evt.User.name_max_len).from(name) orelse return error.RouteTooLong } }); 247 }, 248 .user => { 249 self.session.haxy_moment = try evt.currentMoment(evt.admin_repo_opts, admin_repo); 250 try self.session.forgetSshKey(); 251 self.session.logOut(); 252 try self.session.navigate(.default); 253 }, 254 } 255 } 256 257 pub fn clearGrid(self: *View) void { 258 self.scroll.clearGrid(); 259 } 260 261 pub fn getGrid(self: View) ?Grid { 262 return self.scroll.getGrid(); 263 } 264 265 pub fn getFocus(self: *View) *Focus { 266 return self.scroll.getFocus(); 267 } 268 269 // up leaves the view from the first control 270 pub fn atTop(self: *View, root_focus: *Focus) bool { 271 return root_focus.grandchild_id == self.control_ids[confirm_index]; 272 } 273 }; 274