╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
859 } 860 861 // `dir` with its last segment removed ("" when `dir` has a single segment). 862 fn parentDir(dir: []const u8) []const u8 { 863 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 864 return dir[0..slash]; 865 } 866 867 // the "<ref_or_oid> <value>" banner shown above the listing. 868 pub const Header = struct { 869 content: []const u8, 870 871 // `value` arrives url-encoded, so decode it for display. 872 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 873 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 874 return .{ 875 .content = try std.fmt.allocPrint(aa, "{s} {s}", .{ @tagName(ref_or_oid), decoded }), 876 }; 877 } 878 879 pub const View = struct { 880 box: wgt.Box(ui.Widget), 881 data: *const Header, 882 883 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session, location: ui.RoutablePage.RepoLocation) !Header.View { 884 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 885 errdefer box.deinit(allocator); 886 887 if (session.data.host_kind == .server) { 888 if (try ui.widget.CopyableText.initClone(allocator, session, location)) |value| { 889 var clone_url = value; 890 errdefer clone_url.deinit(allocator); 891 const min_width = clone_url.minWidth(); 892 box.getFocus().child_id = clone_url.getFocus().id; 893 try box.children.put(allocator, clone_url.getFocus().id, .{ .widget = .{ .copyable_text = clone_url }, .rect = null, .min_size = .{ .width = min_width, .height = 3 }, .max_size = .{ .width = min_width, .height = 3 } }); 894 } 895 } 896 897 var spacer = try ui.widget.Spacer.init(allocator); 898 errdefer spacer.deinit(allocator); 899 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 900 901 var text_box = try wgt.TextBox.init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 902 errdefer text_box.deinit(allocator); 903 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null, .flex = .shrink }); 904 905 return .{ .box = box, .data = data }; 906 } 907 908 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 909 self.box.deinit(allocator); 910 } 911 912 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 913 self.clearGrid(); 914 try self.box.build(allocator, constraint, root_focus); 915 } 916 917 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 918 const clone_url = self.cloneUrl() orelse return; 919 try clone_url.input(allocator, key, root_focus); 920 } 921 922 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 923 const clone_url = self.cloneUrl() orelse return false; 924 root_focus.setFocus(clone_url.getFocus().id); 925 return true; 926 } 927 928 pub fn hasCloneUrl(self: *Header.View) bool { 929 return self.cloneUrl() != null; 930 } 931 932 fn cloneUrl(self: *Header.View) ?*ui.widget.CopyableText { 933 for (self.box.children.values()) |*child| switch (child.widget) { 934 .copyable_text => |*copyable_text| return copyable_text, 935 else => {}, 936 }; 937 return null; 938 } 939 940 pub fn clearGrid(self: *Header.View) void { 941 self.box.clearGrid(); 942 } 943 944 pub fn getGrid(self: Header.View) ?Grid { 945 return self.box.getGrid(); 946 } 947 948 pub fn getFocus(self: *Header.View) *Focus { 949 return self.box.getFocus(); 950 } 951 }; 952 }; 953