╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
142 const password_hash = try evt.User.hashPassword("password", &password_hash_buf, io); 143 144 var events_to_consume: [user_data.len + repo_data.len]evt.EventWithId = undefined; 145 for (user_data, 0..) |u, i| { 146 events_to_consume[i] = .{ 147 .id = std.fmt.bytesToHex(user_ids[i], .lower), 148 .event = .{ 149 .user = .{ 150 .name = u.name, 151 .display_name = u.display_name, 152 .email = u.email, 153 .password_hash = password_hash, 154 }, 155 }, 156 }; 157 } 158 for (repo_data, 0..) |r, i| { 159 events_to_consume[user_data.len + i] = .{ 160 .id = std.fmt.bytesToHex(repo_event_ids[i], .lower), 161 .event = .{ 162 .repo = .{ 163 .user_id = &user_ids[r.user_index], 164 .name = r.name, 165 .description = r.description, 166 .enable_issue = true, 167 }, 168 }, 169 }; 170 } 171 172 // insert users and repos as commits in the repo 173 { 174 var json: std.Io.Writer.Allocating = .init(allocator); 175 defer json.deinit(); 176 177 for (events_to_consume) |event| { 178 json.clearRetainingCapacity(); 179 180 try std.json.Stringify.value(event, .{}, &json.writer); 181 182 // commit the event into a special branch 183 _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, .{ .kind = .head, .name = "haxy/meta" }); 184 } 185 } 186 187 // consume events into the database 188 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); 189 190 session = try ui.Session.init(repo_opts, &page_arena, &repo, .{}); 191 break :blk .{ .home = try .init(repo_opts, &page_arena, session.haxy_moment orelse unreachable) }; 192 }; 193 194 // start the server 195 196 var cli = false; 197 198 var arg_it = try init.minimal.args.iterateAllocator(allocator); 199 defer arg_it.deinit(); 200 _ = arg_it.skip(); 201 while (arg_it.next()) |arg| { 202 if (std.mem.eql(u8, "--cli", arg)) { 203 cli = true; 204 } 205 } 206 207 const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); 208 defer allocator.free(server_path); 209 210 if (cli) { 211 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 212 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 213 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 214 215 const Runnable = struct { 216 io: std.Io, 217 218 pub fn run(self: @This()) !void { 219 std.debug.print( 220 \\ 221 \\connect to the TUI with: 222 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 223 \\ 224 \\create a git repo and push over SSH: 225 \\ mkdir -p temp-try/client/test 226 \\ cd temp-try/client/test 227 \\ git init 228 \\ echo "hello" > hello.txt 229 \\ git add hello.txt 230 \\ git commit -m "let there be light" 231 \\ GIT_SSH_COMMAND='ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' git push localhost:test HEAD:master 232 \\ 233 \\to quit, press enter. 234 \\ 235 , .{}); 236 // portable stdin read via std.Io — equivalent to the 237 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 238 // on windows. 239 var buf: [1]u8 = undefined; 240 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 241 _ = stdin_reader.interface.takeByte() catch {}; 242 } 243 }; 244 245 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 246 .data_dir = server_path, 247 }, run_opts.err, Runnable{ .io = io }); 248 } else { 249 var null_writer = std.Io.Writer.Discarding.init(&.{}); 250 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 251 252 const Runnable = struct { 253 io: std.Io, 254 allocator: std.mem.Allocator, 255 page: *const ui.Page, 256 session: *ui.Session, 257 258 pub fn run(self: @This()) !void { 259 // launch the TUI 260 try hx.ui.run(self.io, self.allocator, self.page, self.session); 261 } 262 }; 263 264 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 265 .data_dir = server_path, 266 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .page = &page, .session = &session }); 267 } 268 } 269