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