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