╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2398 const status: evt.Issue.Status = switch (entry.issue.event.status) { 2399 .open => .closed, 2400 .closed => .open, 2401 }; 2402 2403 var id_bytes: [evt.event_id_size]u8 = undefined; 2404 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2405 2406 switch (src.repo_kind) { 2407 inline else => |repo_kind| { 2408 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2409 defer any_repo.deinit(io, allocator); 2410 switch (any_repo) { 2411 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2412 } 2413 }, 2414 } 2415 2416 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, status, "", entry.id) orelse return; 2417 try self.session.navigate(route); 2418 } 2419 2420 // arrow keys move the tag selection; at the flow's edges focus crosses to 2421 // the neighboring widgets. 2422 fn tagsInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 2423 const tf = self.tagFlow(index) orelse return; 2424 const cid = tf.focus.child_id orelse return; 2425 const cur = tf.indexOfFocusId(cid) orelse return; 2426 const count = tf.text_boxes.items.len; 2427 switch (key) { 2428 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2429 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2430 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2431 self.focusTag(index, tf, root_focus, i); 2432 } else { 2433 _ = self.moveDetailVertical(index, root_focus, false); 2434 }, 2435 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2436 self.focusTag(index, tf, root_focus, i); 2437 } else { 2438 _ = self.moveDetailVertical(index, root_focus, true); 2439 }, 2440 .home => self.focusTag(index, tf, root_focus, 0), 2441 .end => self.focusTag(index, tf, root_focus, count - 1), 2442 else => {}, 2443 } 2444 } 2445 2446 const title_child_index: usize = 0; 2447 const tags_child_index: usize = 2; 2448 2449 // the tool row's first child after the spacer that pushes it right 2450 const first_in_row_index: usize = 1; 2451 2452 fn tagFlow(self: *View, index: usize) ?*ui.TagFlow { 2453 const inner = self.detailInner(index); 2454 if (inner.children.count() <= tags_child_index) return null; 2455 return switch (inner.children.values()[tags_child_index].widget) { 2456 .tag_flow => |*tf| tf, 2457 else => null, 2458 }; 2459 } 2460 2461 fn tagsFocused(self: *View, index: usize) bool { 2462 const inner = self.detailInner(index); 2463 const cid = inner.getFocus().child_id orelse return false; 2464 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2465 } 2466 2467 fn toolRowFocused(self: *View, index: usize) bool { 2468 const outer = self.detailOuter(index); 2469 const cid = outer.getFocus().child_id orelse return false; 2470 return outer.children.getIndex(cid) == tool_row_index; 2471 } 2472 2473 fn focusTag(self: *View, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2474 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2475 // keep the tag visible on the terminal: its rect offset by the flow's 2476 // position in the pane. 2477 if (self.session.is_terminal and item < tf.rects.items.len) { 2478 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2479 var rect = tf.rects.items[item]; 2480 rect.x += flow_rect.x; 2481 rect.y += flow_rect.y; 2482 self.detailScroll(index).scrollToRect(rect); 2483 } 2484 } 2485 } 2486 2487 fn titleFocused(self: *View, index: usize) bool { 2488 const inner = self.detailInner(index); 2489 const cid = inner.getFocus().child_id orelse return false; 2490 return inner.children.getIndex(cid) == title_child_index; 2491 } 2492 2493 fn authorFocused(self: *View, index: usize) bool { 2494 const inner = self.detailInner(index); 2495 const cid = inner.getFocus().child_id orelse return false; 2496 return cid == self.author_id[index]; 2497 } 2498 2499 fn descriptionFocused(self: *View, index: usize) bool { 2500 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2501 return cid == self.description_id[index]; 2502 } 2503 2504 // return to the tool row's last-focused button (the header when the 2505 // description page shows no row). 2506 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 2507 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2508 root_focus.setFocus(cid); 2509 } 2510 2511 // enter the detail pane. an empty pane (no issues) can't be entered. 2512 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 2513 if (self.detailInner(index).children.count() == 0) return; 2514 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2515 } 2516 2517 // return to the list. 2518 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 2519 root_focus.setFocus(self.listScroll(index).getFocus().id); 2520 } 2521 2522 // cross to the header tabs above the stack. 2523 fn focusHeader(self: *View, root_focus: *Focus) void { 2524 root_focus.setFocus(self.box.children.keys()[header_index]); 2525 } 2526 2527 pub fn clearGrid(self: *View) void { 2528 self.box.clearGrid(); 2529 } 2530 2531 pub fn getGrid(self: View) ?Grid { 2532 return self.box.getGrid(); 2533 } 2534 2535 pub fn getFocus(self: *View) *Focus { 2536 return self.box.getFocus(); 2537 } 2538 2539 // for the parent's "scroll up at the top jumps to the header" check: at the 2540 // top only while the header tabs hold focus, so up from the split 2541 // crosses into the tabs first. 2542 pub fn getSelectedIndex(self: *View) ?usize { 2543 return if (self.headerActive()) 0 else 1; 2544 } 2545 }; 2546 2547 // the "a:" navigation link for `status`'s issues page filtered to the 2548 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 2549 // a rooted url ignores `status` (it derives its view from the issue's own); 2550 // with an empty `id` this is the bare list link. 2551 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 2552 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 2553 const url = try route.toUrl(page_arena); 2554 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2555 } 2556 2557 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 2558 // href is only followed with js off. 2559 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2560 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 2561 const url = try route.toUrl(page_arena); 2562 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 2563 } 2564 2565 // the "a:" link to the window `status_maybe` names, keeping the tag filter, 2566 // or the conflicts window when null, rooted at issue `id`. 2567 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?evt.Issue.Status, id: []const u8) ![]const u8 { 2568 if (status_maybe) |status| return issuesLink(page_arena, data.identity, status, data.tag, id); 2569 return conflictsLink(page_arena, data.identity, id); 2570 } 2571 2572 // the "a:" link to the conflicts list rooted at issue `start` ("" = the 2573 // first window). 2574 fn conflictsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start: []const u8) ![]const u8 { 2575 const route = ui.RoutablePage.repoIssuesConflictsRoute(identity, start) orelse return error.RouteTooLong; 2576 const url = try route.toUrl(page_arena); 2577 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2578 } 2579 2580 // the "a:" link to the whole-description page of issue `id` within `identity`. 2581 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2582 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 2583 const url = try route.toUrl(page_arena); 2584 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2585 } 2586 2587 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 2588 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 2589 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 2590 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 2591 const url = try route.toUrl(page_arena); 2592 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2593 } 2594 2595 // tabs switching between the issues page's views. 2596 pub const Header = struct { 2597 box: wgt.Box(ui.Widget), 2598 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 2599 2600 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 2601 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 2602 errdefer box.deinit(allocator); 2603 2604 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 2605 errdefer tab_ids.deinit(allocator); 2606 2607 const aa = session.page_arena.allocator(); 2608 2609 // a list tab per status, labeled with its listing's issue count 2610 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 2611 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 2612 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2613 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 2614 try addTab(allocator, &box, &tab_ids, label, link); 2615 } 2616 2617 // tags tab, labeled with the active tag filter 2618 { 2619 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 2620 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 2621 const label = if (data.tag.len == 0) "tags" else blk: { 2622 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 2623 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 2624 }; 2625 try addTab(allocator, &box, &tab_ids, label, tags_link); 2626 } 2627 2628 // new-issue tab; an edit or resolve url shows its tab in this place 2629 { 2630 const route = switch (data.view) { 2631 .edit => ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 2632 .new_comment => ui.RoutablePage.repoCommentNewRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 2633 .edit_comment => ui.RoutablePage.repoCommentEditRoute(data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 2634 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 2635 else => ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong, 2636 }; 2637 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2638 const label: []const u8 = switch (data.view) { 2639 .edit => "edit", 2640 .new_comment => "reply", 2641 .edit_comment => "edit", 2642 .resolve => "resolve", 2643 else => "new", 2644 }; 2645 try addTab(allocator, &box, &tab_ids, label, link); 2646 } 2647 2648 // conflicts tab, labeled with the conflict count 2649 if (data.conflicts.count > 0) { 2650 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2651 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2652 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2653 try addTab(allocator, &box, &tab_ids, label, link); 2654 } 2655 2656 var self = Header{ .box = box, .tab_ids = tab_ids }; 2657 // the tab matching the page's view is selected initially. 2658 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2659 return self; 2660 } 2661 2662 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2663 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2664 errdefer text_box.deinit(allocator); 2665 text_box.getFocus().focusable = true; 2666 text_box.getFocus().kind = .{ .custom = link }; 2667 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2668 try box.children.put(allocator, text_box.getFocus().id, .{ 2669 .widget = .{ .text_box = text_box }, 2670 .rect = null, 2671 .min_size = .{ .width = label.len + 2, .height = null }, 2672 }); 2673 } 2674 2675 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2676 self.box.deinit(allocator); 2677 self.tab_ids.deinit(allocator); 2678 } 2679 2680 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2681 self.clearGrid(); 2682 // only the selected tab shows its border 2683 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2684 switch (child.widget) { 2685 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2686 else => {}, 2687 } 2688 } 2689 try self.box.build(allocator, constraint, root_focus); 2690 } 2691 2692 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2693 _ = allocator; 2694 const current_tab = self.currentTabIndex() orelse return; 2695 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2696 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2697 } 2698 } 2699 2700 pub fn clearGrid(self: *Header) void { 2701 self.box.clearGrid(); 2702 } 2703 2704 pub fn getGrid(self: Header) ?Grid { 2705 return self.box.getGrid(); 2706 } 2707 2708 pub fn getFocus(self: *Header) *Focus { 2709 return self.box.getFocus(); 2710 } 2711 2712 pub fn getSelectedIndex(self: Header) ?usize { 2713 return self.currentTabIndex(); 2714 } 2715 2716 fn currentTabIndex(self: Header) ?usize { 2717 const child_id = self.box.focus.child_id orelse return null; 2718 return self.tab_ids.getIndex(child_id); 2719 } 2720 }; 2721