╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
989 if (std.ascii.isAlphanumeric(char)) { 990 const needed: usize = if (pending == null) 1 else 2; 991 if (len + needed > name.len) break; 992 if (pending) |value| { 993 name[len] = value; 994 len += 1; 995 } 996 name[len] = std.ascii.toLower(char); 997 len += 1; 998 pending = null; 999 } else if (char == ' ') { 1000 if (len != 0) pending = '-'; 1001 } else if (char == '.') { 1002 if (len != 0 and pending != '-') pending = '.'; 1003 } 1004 } 1005 if (len == 0) return ""; 1006 return allocator.dupe(u8, name[0..len]); 1007 } 1008 1009 // tabs switching between the patches page's views 1010 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1011 var header = try Header.init(allocator, session, data.search); 1012 errdefer header.deinit(allocator); 1013 const aa = session.page_arena.allocator(); 1014 const selected_index = View.viewIndex(data.view); 1015 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1016 1017 // a list tab per status, labeled with its listing's patch count 1018 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1019 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1020 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, data.tag, ""), data.search); 1021 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1022 var label_buf: [64]u8 = undefined; 1023 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1024 try header.addTab(allocator, label, link, index); 1025 } 1026 1027 // tags tab, labeled with the active tag filter 1028 { 1029 const tags_route = try thread.searchRoute(ui.RoutablePage.repoThreadTagsRoute(.patch, data.identity, data.tag), data.search); 1030 const tags_link = try ui.inPageTabLink(session, tags_route, page_selected and selected_index == View.viewIndex(.tags)); 1031 const label = if (data.tag.len == 0) tags_tab_label else blk: { 1032 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1033 break :blk try std.fmt.allocPrint(aa, tags_tab_label ++ " ({s})", .{decoded}); 1034 }; 1035 try header.addTab(allocator, label, tags_link, View.viewIndex(.tags)); 1036 } 1037 1038 // new-patch tab; an edit or resolve url shows its tab in this place 1039 { 1040 const route = switch (data.view) { 1041 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1042 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1043 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1044 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1045 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1046 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1047 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1048 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1049 }; 1050 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1051 const label: []const u8 = switch (data.view) { 1052 .edit => edit_tab_label, 1053 .publish => publish_tab_label, 1054 .merge => merge_tab_label, 1055 .new_comment => reply_tab_label, 1056 .edit_comment => edit_tab_label, 1057 .remove => remove_tab_label, 1058 .resolve => resolve_tab_label, 1059 else => new_tab_label, 1060 }; 1061 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1062 } 1063 1064 // drafts belong to the logged-in user and are not available locally 1065 if (session.data.host_kind != .local) { 1066 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1067 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1068 var label_buf: [64]u8 = undefined; 1069 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1070 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1071 } 1072 1073 // conflicts tab, labeled with the conflict count 1074 if (data.conflicts.count > 0) { 1075 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1076 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1077 var label_buf: [64]u8 = undefined; 1078 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1079 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1080 } 1081 1082 header.select(View.viewIndex(data.view)); 1083 return header; 1084 } 1085