a modern tui library written in zig

Update to Zig 0.15.0-dev.1160+e43617e68

authored by Ivan Stepanov and committed by rockorager.dev 1bf887aa cc9154d5

Changed files
+50 -39
examples
src
+26 -17
build.zig
··· 45 45 const example_step = b.step("example", "Run example"); 46 46 const example = b.addExecutable(.{ 47 47 .name = "example", 48 - // future versions should use b.path, see zig PR #19597 49 - .root_source_file = b.path( 50 - b.fmt("examples/{s}.zig", .{@tagName(example_option)}), 51 - ), 52 - .target = target, 53 - .optimize = optimize, 48 + .root_module = b.createModule(.{ 49 + .root_source_file = b.path( 50 + b.fmt("examples/{s}.zig", .{@tagName(example_option)}), 51 + ), 52 + .target = target, 53 + .optimize = optimize, 54 + .imports = &.{ 55 + .{ .name = "vaxis", .module = vaxis_mod }, 56 + }, 57 + }), 54 58 }); 55 - example.root_module.addImport("vaxis", vaxis_mod); 56 59 57 60 const example_run = b.addRunArtifact(example); 58 61 example_step.dependOn(&example_run.step); ··· 61 64 const tests_step = b.step("test", "Run tests"); 62 65 63 66 const tests = b.addTest(.{ 64 - .root_source_file = b.path("src/main.zig"), 65 - .target = target, 66 - .optimize = optimize, 67 + .root_module = b.createModule(.{ 68 + .root_source_file = b.path("src/main.zig"), 69 + .target = target, 70 + .optimize = optimize, 71 + .imports = &.{ 72 + .{ .name = "code_point", .module = zg_dep.module("code_point") }, 73 + .{ .name = "Graphemes", .module = zg_dep.module("Graphemes") }, 74 + .{ .name = "DisplayWidth", .module = zg_dep.module("DisplayWidth") }, 75 + .{ .name = "zigimg", .module = zigimg_dep.module("zigimg") }, 76 + }, 77 + }), 67 78 }); 68 - tests.root_module.addImport("code_point", zg_dep.module("code_point")); 69 - tests.root_module.addImport("Graphemes", zg_dep.module("Graphemes")); 70 - tests.root_module.addImport("DisplayWidth", zg_dep.module("DisplayWidth")); 71 - tests.root_module.addImport("zigimg", zigimg_dep.module("zigimg")); 72 79 73 80 const tests_run = b.addRunArtifact(tests); 74 81 b.installArtifact(tests); ··· 78 85 const docs_step = b.step("docs", "Build the vaxis library docs"); 79 86 const docs_obj = b.addObject(.{ 80 87 .name = "vaxis", 81 - .root_source_file = root_source_file, 82 - .target = target, 83 - .optimize = optimize, 88 + .root_module = b.createModule(.{ 89 + .root_source_file = root_source_file, 90 + .target = target, 91 + .optimize = optimize, 92 + }), 84 93 }); 85 94 const docs = docs_obj.getEmittedDocs(); 86 95 docs_step.dependOn(&b.addInstallDirectory(.{
+6 -4
build.zig.zon
··· 5 5 .minimum_zig_version = "0.14.0", 6 6 .dependencies = .{ 7 7 .zigimg = .{ 8 - .url = "git+https://github.com/zigimg/zigimg#74caab5edd7c5f1d2f7d87e5717435ce0f0affa1", 9 - .hash = "zigimg-0.1.0-8_eo2nWlEgCddu8EGLOM_RkYshx3sC8tWv-yYA4-htS6", 8 + // TODO .url = "git+https://github.com/zigimg/zigimg", 9 + .url = "git+https://github.com/ivanstepanovftw/zigimg#aa4c31db872612c39edbb79f753b3cd9a79fe726", 10 + .hash = "zigimg-0.1.0-8_eo2mWmEgBoqdr0sH9O5GTqDHthkoEPM5_tipcBRreL", 10 11 }, 11 12 .zg = .{ 12 - .url = "git+https://codeberg.org/atman/zg#0b05141b033043c5f7bcd72048a48eef6531ea6c", 13 - .hash = "zg-0.14.0-oGqU3KEFswIffnDu8eAE2XlhzwcfgjwtM6akIc5L7cEV", 13 + // TODO .url = "git+https://codeberg.org/atman/zg", 14 + .url = "git+https://codeberg.org/ivanstepanovftw/zg#4fe689e56ce2ed5a8f59308b471bccd7da89fac9", 15 + .hash = "zg-0.14.1-oGqU3J4_tAKBfyes3AWleKDjo-IcYvnEwaB8qxOqFMwM", 14 16 }, 15 17 }, 16 18 .paths = .{
+1 -1
examples/vaxis.zig
··· 83 83 // try vx.render(bw.writer().any()); 84 84 // try bw.flush(); 85 85 try vx.render(tty.anyWriter()); 86 - std.time.sleep(16 * std.time.ns_per_ms); 86 + std.Thread.sleep(16 * std.time.ns_per_ms); 87 87 switch (dir) { 88 88 .up => { 89 89 pct += 1;
+1 -1
examples/vt.zig
··· 61 61 62 62 var redraw: bool = false; 63 63 while (true) { 64 - std.time.sleep(8 * std.time.ns_per_ms); 64 + std.Thread.sleep(8 * std.time.ns_per_ms); 65 65 // try vt events first 66 66 while (vt.tryEvent()) |event| { 67 67 redraw = true;
+1 -1
src/Parser.zig
··· 116 116 117 117 // Check if we have a multi-codepoint grapheme 118 118 var code = cp.code; 119 - var g_state: Graphemes.State = .{}; 119 + var g_state: Graphemes.IterState = .{}; 120 120 var prev_cp = code; 121 121 while (iter.next()) |next_cp| { 122 122 if (Graphemes.graphemeBreak(prev_cp, next_cp.code, data, &g_state)) {
+7 -7
src/queue.zig
··· 220 220 // still full and the push in the other thread is still blocked 221 221 // waiting for space. 222 222 try Thread.yield(); 223 - std.time.sleep(std.time.ns_per_s); 223 + std.Thread.sleep(std.time.ns_per_s); 224 224 // Finally, let that other thread go. 225 225 try std.testing.expectEqual(1, q.pop()); 226 226 ··· 230 230 try Thread.yield(); 231 231 // But we want to ensure that there's a second push waiting, so 232 232 // here's another sleep. 233 - std.time.sleep(std.time.ns_per_s / 2); 233 + std.Thread.sleep(std.time.ns_per_s / 2); 234 234 235 235 // Another spurious wake... 236 236 q.not_full.signal(); ··· 238 238 // And another chance for the other thread to see that it's 239 239 // spurious and go back to sleep. 240 240 try Thread.yield(); 241 - std.time.sleep(std.time.ns_per_s / 2); 241 + std.Thread.sleep(std.time.ns_per_s / 2); 242 242 243 243 // Pop that thing and we're done. 244 244 try std.testing.expectEqual(2, q.pop()); ··· 275 275 fn sleepyPush(q: *Queue(u8, 1)) !void { 276 276 // Try to ensure the other thread has already started trying to pop. 277 277 try Thread.yield(); 278 - std.time.sleep(std.time.ns_per_s / 2); 278 + std.Thread.sleep(std.time.ns_per_s / 2); 279 279 280 280 // Spurious wake 281 281 q.not_full.signal(); 282 282 q.not_empty.signal(); 283 283 284 284 try Thread.yield(); 285 - std.time.sleep(std.time.ns_per_s / 2); 285 + std.Thread.sleep(std.time.ns_per_s / 2); 286 286 287 287 // Stick something in the queue so it can be popped. 288 288 q.push(1); ··· 291 291 try Thread.yield(); 292 292 // Give the other thread time to block again. 293 293 try Thread.yield(); 294 - std.time.sleep(std.time.ns_per_s / 2); 294 + std.Thread.sleep(std.time.ns_per_s / 2); 295 295 296 296 // Spurious wake 297 297 q.not_full.signal(); ··· 322 322 const t1 = try Thread.spawn(cfg, readerThread, .{&queue}); 323 323 const t2 = try Thread.spawn(cfg, readerThread, .{&queue}); 324 324 try Thread.yield(); 325 - std.time.sleep(std.time.ns_per_s / 2); 325 + std.Thread.sleep(std.time.ns_per_s / 2); 326 326 queue.push(1); 327 327 queue.push(1); 328 328 t1.join();
+3 -3
src/tty.zig
··· 59 59 .handler = .{ .handler = PosixTty.handleWinch }, 60 60 .mask = switch (builtin.os.tag) { 61 61 .macos => 0, 62 - else => posix.empty_sigset, 62 + else => posix.sigemptyset(), 63 63 }, 64 64 .flags = 0, 65 65 }; ··· 93 93 .handler = .{ .handler = posix.SIG.DFL }, 94 94 .mask = switch (builtin.os.tag) { 95 95 .macos => 0, 96 - else => posix.empty_sigset, 96 + else => posix.sigemptyset(), 97 97 }, 98 98 .flags = 0, 99 99 }; ··· 143 143 handler_idx += 1; 144 144 } 145 145 146 - fn handleWinch(_: c_int) callconv(.C) void { 146 + fn handleWinch(_: c_int) callconv(.c) void { 147 147 handler_mutex.lock(); 148 148 defer handler_mutex.unlock(); 149 149 var i: usize = 0;
+1 -1
src/vxfw/App.zig
··· 113 113 next_frame_ms = now_ms + tick_ms; 114 114 } else { 115 115 // Sleep until the deadline 116 - std.time.sleep((next_frame_ms - now_ms) * std.time.ns_per_ms); 116 + std.Thread.sleep((next_frame_ms - now_ms) * std.time.ns_per_ms); 117 117 next_frame_ms += tick_ms; 118 118 } 119 119
+3 -3
src/vxfw/vxfw.zig
··· 550 550 file.name[0..idx] 551 551 else 552 552 continue; 553 - const data = try cwd.readFileAllocOptions(std.testing.allocator, file.name, 10_000_000, null, @alignOf(u8), 0x00); 553 + const data = try cwd.readFileAllocOptions(std.testing.allocator, file.name, 10_000_000, null, .of(u8), 0x00); 554 554 defer std.testing.allocator.free(data); 555 555 var ast = try std.zig.Ast.parse(std.testing.allocator, data, .zig); 556 556 defer ast.deinit(std.testing.allocator); ··· 558 558 var has_doctest: bool = false; 559 559 var has_refAllDecls: bool = false; 560 560 for (ast.rootDecls()) |root_decl| { 561 - const decl = ast.nodes.get(root_decl); 561 + const decl = ast.nodes.get(@intFromEnum(root_decl)); 562 562 switch (decl.tag) { 563 563 .test_decl => { 564 - const test_name = ast.tokenSlice(decl.data.lhs); 564 + const test_name = ast.tokenSlice(decl.main_token + 1); 565 565 if (std.mem.eql(u8, "\"refAllDecls\"", test_name)) 566 566 has_refAllDecls = true 567 567 else if (std.mem.eql(u8, container_name, test_name))
+1 -1
src/widgets/terminal/Command.zig
··· 64 64 .handler = .{ .handler = handleSigChild }, 65 65 .mask = switch (builtin.os.tag) { 66 66 .macos => 0, 67 - .linux => posix.empty_sigset, 67 + .linux => posix.sigemptyset(), 68 68 else => @compileError("os not supported"), 69 69 }, 70 70 .flags = 0,