╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
812 // page with that file selected and its content read. 813 fn fileLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, path: []const u8, loaded: bool) ![]const u8 { 814 const route = ui.RoutablePage.repoFilesRoute(data.identity, data.ref_or_oid, data.ref_or_oid_value, path, 0) orelse return error.RouteTooLong; 815 const prefix = if (loaded) "ai:" else "a:"; 816 return std.fmt.allocPrint(page_arena.allocator(), "{s}{s}", .{ prefix, try route.toUrl(page_arena) }); 817 } 818 819 // the url `line` value for a content window: its first line's 1-based number, 820 // except the first window, which serializes as unset (0). 821 fn lineNumber(window_start: usize) usize { 822 return if (window_start == 0) 0 else window_start + 1; 823 } 824 825 // `dir`/`name`, or just `name` at the root. 826 pub fn childDir(arena: std.mem.Allocator, dir: []const u8, name: []const u8) ![]const u8 { 827 return if (dir.len == 0) name else std.fmt.allocPrint(arena, "{s}/{s}", .{ dir, name }); 828 } 829 830 // `dir` with its last segment removed ("" when `dir` has a single segment). 831 fn parentDir(dir: []const u8) []const u8 { 832 const slash = std.mem.lastIndexOfScalar(u8, dir, '/') orelse return ""; 833 return dir[0..slash]; 834 } 835 836 // the "viewing <ref_or_oid> <value>" banner shown above the listing. 837 pub const Header = struct { 838 content: []const u8, 839 840 // `value` arrives url-encoded, so decode it for display. 841 pub fn init(aa: std.mem.Allocator, ref_or_oid: ui.RoutablePage.RefOrOid, value: []const u8) !Header { 842 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, value)); 843 return .{ 844 .content = try std.fmt.allocPrint(aa, "viewing {s} {s}", .{ @tagName(ref_or_oid), decoded }), 845 }; 846 } 847 848 pub const View = struct { 849 box: wgt.Box(ui.Widget), 850 data: *const Header, 851 852 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session) !Header.View { 853 _ = session; 854 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 855 errdefer box.deinit(allocator); 856 857 var text_box = try wgt.TextBox(ui.Widget).init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 858 errdefer text_box.deinit(allocator); 859 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null }); 860 861 return .{ .box = box, .data = data }; 862 } 863 864 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 865 self.box.deinit(allocator); 866 } 867 868 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 869 self.clearGrid(); 870 try self.box.build(allocator, constraint, root_focus); 871 } 872 873 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 874 _ = self; 875 _ = allocator; 876 _ = key; 877 _ = root_focus; 878 } 879 880 pub fn clearGrid(self: *Header.View) void { 881 self.box.clearGrid(); 882 } 883 884 pub fn getGrid(self: Header.View) ?Grid { 885 return self.box.getGrid(); 886 } 887 888 pub fn getFocus(self: *Header.View) *Focus { 889 return self.box.getFocus(); 890 } 891 }; 892 }; 893