╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
978 }) orelse return error.RouteTooLong; 979 const url = try route.toUrl(page_arena); 980 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 981 } 982 983 // the "a:" link to the page showing `oid`'s message on its own. 984 fn messageLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, oid: []const u8) ![]const u8 { 985 const route = ui.RoutablePage.repoCommitMessageRoute(identity, .object, oid) orelse return error.RouteTooLong; 986 const url = try route.toUrl(page_arena); 987 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 988 } 989 990 // the "<ref_or_oid> <value>" banner shown above the log. 991 pub const Header = struct { 992 content: []const u8, 993 994 // `value` arrives url-encoded, so decode it for display. 995 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 996 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 997 return .{ 998 .content = try std.fmt.allocPrint(aa, "{s} {s}", .{ @tagName(ref_or_oid), decoded }), 999 }; 1000 } 1001 1002 pub const View = struct { 1003 box: wgt.Box(ui.Widget), 1004 data: *const Header, 1005 1006 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session, identity: []const u8) !Header.View { 1007 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1008 errdefer box.deinit(allocator); 1009 1010 if (!session.data.is_local and (session.data.clone_http_port != null or session.data.clone_ssh_port != null)) { 1011 var clone_url = try ui.CloneUrl.View.init(allocator, session, identity); 1012 errdefer clone_url.deinit(allocator); 1013 const min_width = clone_url.minWidth(); 1014 box.getFocus().child_id = clone_url.getFocus().id; 1015 try box.children.put(allocator, clone_url.getFocus().id, .{ .widget = .{ .clone_url = clone_url }, .rect = null, .min_size = .{ .width = min_width, .height = 3 } }); 1016 } 1017 1018 var spacer = try ui.Spacer.init(allocator); 1019 errdefer spacer.deinit(allocator); 1020 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1021 1022 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 1023 errdefer text_box.deinit(allocator); 1024 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null, .flex = .shrink }); 1025 1026 return .{ .box = box, .data = data }; 1027 } 1028 1029 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 1030 self.box.deinit(allocator); 1031 } 1032 1033 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1034 self.clearGrid(); 1035 try self.box.build(allocator, constraint, root_focus); 1036 } 1037 1038 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1039 const clone_url = self.cloneUrl() orelse return; 1040 try clone_url.input(allocator, key, root_focus); 1041 } 1042 1043 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 1044 const clone_url = self.cloneUrl() orelse return false; 1045 root_focus.setFocus(clone_url.getFocus().id); 1046 return true; 1047 } 1048 1049 pub fn hasCloneUrl(self: *Header.View) bool { 1050 return self.cloneUrl() != null; 1051 } 1052 1053 fn cloneUrl(self: *Header.View) ?*ui.CloneUrl.View { 1054 for (self.box.children.values()) |*child| switch (child.widget) { 1055 .clone_url => |*clone_url| return clone_url, 1056 else => {}, 1057 }; 1058 return null; 1059 } 1060 1061 pub fn clearGrid(self: *Header.View) void { 1062 self.box.clearGrid(); 1063 } 1064 1065 pub fn getGrid(self: Header.View) ?Grid { 1066 return self.box.getGrid(); 1067 } 1068 1069 pub fn getFocus(self: *Header.View) *Focus { 1070 return self.box.getFocus(); 1071 } 1072 }; 1073 }; 1074