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