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