╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
398 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 399 // on windows. 400 var buf: [1]u8 = undefined; 401 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 402 _ = stdin_reader.interface.takeByte() catch {}; 403 } 404 }; 405 406 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 407 .data_dir = server_path, 408 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 409 } else { 410 var null_writer = std.Io.Writer.Discarding.init(&.{}); 411 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 412 413 const Runnable = struct { 414 io: std.Io, 415 allocator: std.mem.Allocator, 416 session: *ui.Session, 417 418 pub fn run(self: @This()) !void { 419 // launch the TUI 420 try hx.ui.run(self.io, self.allocator, self.session); 421 } 422 }; 423 424 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 425 .data_dir = server_path, 426 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session }); 427 } 428 } 429 430 // words cycled through to pad generated lines into prose-like content 431 const scatter_words = [_][]const u8{ 432 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 433 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 434 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 435 "scatter", "gather", "encode", "decode", "render", "commit", 436 }; 437 438 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 439 // index `fi` shift which lines change and the words used, so each (c, fi) 440 // yields a distinct multi-hunk diff against the previous revision. untouched 441 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 442 // small hunks rather than a full rewrite. 443 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 444 const file = try repo_dir.createFile(io, path, .{}); 445 defer file.close(io); 446 var writer = std.Io.Writer.Allocating.init(allocator); 447 defer writer.deinit(); 448 for (0..40) |line| { 449 const start = writer.written().len; 450 if ((line + fi + c) % 8 == 0) { 451 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 452 try writer.writer.print("rev {d} {s}", .{ c, tag }); 453 } 454 const target = 40 + (line * 17 + fi * 23) % 70; 455 var w = line + fi; 456 while (true) : (w += 1) { 457 const word = scatter_words[w % scatter_words.len]; 458 const len = writer.written().len - start; 459 if (len >= target or len + 1 + word.len > 120) break; 460 if (len == 0) 461 try writer.writer.print("{s}", .{word}) 462 else 463 try writer.writer.print(" {s}", .{word}); 464 } 465 try writer.writer.writeByte('\n'); 466 } 467 try file.writeStreamingAll(io, writer.written()); 468 } 469 470 // tag the current HEAD as the next sequential version: v1, v2, and so on 471 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 472 var buf: [16]u8 = undefined; 473 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 474 _ = try repo.addTag(io, allocator, .{ .name = name }); 475 n.* += 1; 476 } 477 478 // recursively copy the contents of src_dir into dest_dir 479 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 480 var iter = src_dir.iterate(); 481 while (try iter.next(io)) |entry| { 482 switch (entry.kind) { 483 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 484 .directory => { 485 try dest_dir.createDirPath(io, entry.name); 486 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 487 defer dest_entry_dir.close(io); 488 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 489 defer src_entry_dir.close(io); 490 try copyDir(io, src_entry_dir, dest_entry_dir); 491 }, 492 else => {}, 493 } 494 } 495 } 496