╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
90 .local => { 91 // session-lifetime allocations (the repo path, session state) 92 var session_arena = std.heap.ArenaAllocator.init(allocator); 93 defer session_arena.deinit(); 94 95 // probe both backends for a repo; the nearest one wins, so a repo 96 // isn't shadowed by one it is nested inside. only the work path 97 // and backend kind are kept; pages re-open the repo on each build. 98 const local: ui.RepoSource = blk: { 99 var found: ?ui.RepoSource = null; 100 inline for ([_]rp.RepoKind{ .git, .xit }) |probe_kind| { 101 if (rp.AnyRepo(probe_kind, .{}).open(io, allocator, .{ .path = cwd_path })) |repo| { 102 var opened = repo; 103 defer opened.deinit(io, allocator); 104 const work_path = switch (opened) { 105 inline else => |*r| r.core.work_path, 106 }; 107 const found_len = if (found) |f| f.path.len else 0; 108 if (work_path.len > found_len) { 109 found = .{ 110 .path = try session_arena.allocator().dupe(u8, work_path), 111 .repo_kind = probe_kind, 112 .global_config_path = run_opts.global_config_path, 113 }; 114 } 115 } else |err| switch (err) { 116 error.RepoNotFound => {}, 117 else => |e| return e, 118 } 119 } 120 break :blk found orelse { 121 try run_opts.err.print("no git or xit repo found in the current directory\n", .{}); 122 return error.HandledError; 123 }; 124 }; 125 126 var session = ui.Session{ 127 .arena = &session_arena, 128 .page_arena = &session_arena, 129 .io = io, 130 .local = local, 131 .is_terminal = true, 132 .data = .{ 133 // the files root; local routes carry no identity 134 .current_page = .{ .repo_files = .{ .name = .{} } }, 135 .host_kind = .local, 136 }, 137 }; 138 139 // serve the web UI in the background while the TUI runs in the 140 // foreground; the footer points at whatever port it bound. 141 const Runnable = struct { 142 io: std.Io, 143 allocator: std.mem.Allocator, 144 session: *ui.Session, 145 146 pub fn run(self: @This(), web_port: u16) !void { 147 self.session.web_port = web_port; 148 try ui.run(self.io, self.allocator, self.session, null); 149 } 150 }; 151 152 try srv.runLocal(io, allocator, local, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session }); 153 }, 154 .cli => |cli_cmd| switch (cli_cmd) { 155 .serve => |options| try srv.run(repo_kind, any_repo_opts, io, allocator, cwd_path, options, run_opts.err, {}), 156 }, 157 } 158 } 159