this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

more testing and some cleanups for 0.16

authored by

Jeffrey C. Ollie and committed by
Tim Culverhouse
86b56cf1 4445d39f

+166 -38
+7 -18
README.md
··· 9 9 Libvaxis _does not use terminfo_. Support for vt features is detected through 10 10 terminal queries. 11 11 12 - Vaxis uses zig `0.15.1`. 12 + Vaxis uses zig `0.16.0`. 13 13 14 14 ## Features 15 15 ··· 277 277 foo: u8, 278 278 }; 279 279 280 - pub fn main() !void { 281 - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 282 - defer { 283 - const deinit_status = gpa.deinit(); 284 - //fail test; can't try in defer as defer is executed after we return 285 - if (deinit_status == .leak) { 286 - std.log.err("memory leak", .{}); 287 - } 288 - } 289 - const alloc = gpa.allocator(); 280 + pub fn main(init: std.process.Init) !void { 281 + const io = init.io; 282 + const alloc = init.gpa; 290 283 291 284 // Initialize a tty 292 285 var buffer: [1024]u8 = undefined; 293 - var tty = try vaxis.Tty.init(&buffer); 286 + var tty = try vaxis.Tty.init(io, &buffer); 294 287 defer tty.deinit(); 295 288 296 289 // Initialize Vaxis 297 - var vx = try vaxis.init(alloc, .{}); 290 + var vx = try vaxis.init(io, alloc, init.environ_map, .{}); 298 291 // deinit takes an optional allocator. If your program is exiting, you can 299 292 // choose to pass a null allocator to save some exit time. 300 293 defer vx.deinit(alloc, tty.writer()); ··· 305 298 // installs a signal handler for SIGWINCH on posix TTYs 306 299 // 307 300 // This event loop is thread safe. It reads the tty in a separate thread 308 - var loop: vaxis.Loop(Event) = .{ 309 - .tty = &tty, 310 - .vaxis = &vx, 311 - }; 312 - try loop.init(); 301 + var loop: vaxis.Loop(Event) = .init(io, &tty, &vx); 313 302 314 303 // Start the read loop. This puts the terminal in raw mode and begins 315 304 // reading user input
+11
build.zig
··· 110 110 }), 111 111 }); 112 112 113 + // Let's make sure that all of the examples compile and can run any tests 114 + // that they may have defined. 115 + var it = examples.iterator(); 116 + while (it.next()) |v| { 117 + const e = b.addTest(.{ 118 + .root_module = v.value.*, 119 + }); 120 + const r = b.addRunArtifact(e); 121 + tests_step.dependOn(&r.step); 122 + } 123 + 113 124 const tests_run = b.addRunArtifact(tests); 114 125 b.installArtifact(tests); 115 126 tests_step.dependOn(&tests_run.step);
+4
examples/cli.zig
··· 102 102 focus_in, 103 103 foo: u8, 104 104 }; 105 + 106 + test { 107 + std.testing.refAllDecls(@This()); 108 + }
+4
examples/counter.zig
··· 136 136 137 137 try app.run(model.widget(), .{}); 138 138 } 139 + 140 + test { 141 + std.testing.refAllDecls(@This()); 142 + }
+4
examples/fuzzy.zig
··· 240 240 return 130; 241 241 } 242 242 } 243 + 244 + test { 245 + std.testing.refAllDecls(@This()); 246 + }
+4
examples/image.zig
··· 73 73 try vx.render(tty.writer()); 74 74 } 75 75 } 76 + 77 + // test { 78 + // std.testing.refAllDecls(@This()); 79 + // }
+4
examples/list_view.zig
··· 95 95 96 96 try app.run(model.widget(), .{}); 97 97 } 98 + 99 + test { 100 + std.testing.refAllDecls(@This()); 101 + }
+4
examples/main.zig
··· 119 119 focus_in, 120 120 foo: u8, 121 121 }; 122 + 123 + test { 124 + std.testing.refAllDecls(@This()); 125 + }
+4
examples/scroll.zig
··· 210 210 211 211 try app.run(model.widget(), .{}); 212 212 } 213 + 214 + test { 215 + std.testing.refAllDecls(@This()); 216 + }
+4
examples/split_view.zig
··· 70 70 71 71 try app.run(model.widget(), .{}); 72 72 } 73 + 74 + test { 75 + std.testing.refAllDecls(@This()); 76 + }
+4
examples/table.zig
··· 347 347 .{ .first = "Tyler", .last = "Sanders", .user = "bennettjessica", .email = null, .phone = "1966269423" }, 348 348 .{ .first = "Pamela", .last = "Carter", .user = "zsnyder", .email = null, .phone = "125-062-9130x58413" }, 349 349 }; 350 + 351 + test { 352 + std.testing.refAllDecls(@This()); 353 + }
+4
examples/text_input.zig
··· 149 149 try writer.flush(); 150 150 } 151 151 } 152 + 153 + test { 154 + std.testing.refAllDecls(@This()); 155 + }
+4
examples/text_view.zig
··· 57 57 try tty.writer().flush(); 58 58 } 59 59 } 60 + 61 + test { 62 + std.testing.refAllDecls(@This()); 63 + }
+4
examples/vaxis.zig
··· 110 110 @min(b_a + b_b, 255), 111 111 } }; 112 112 } 113 + 114 + test { 115 + std.testing.refAllDecls(@This()); 116 + }
+4
examples/view.zig
··· 349 349 @setEvalBranchQuota(100_000); 350 350 break :mapHeight @intCast(mem.count(u8, lg_world_map, "\n")); 351 351 }; 352 + 353 + test { 354 + std.testing.refAllDecls(@This()); 355 + }
+4
examples/vt.zig
··· 102 102 try vx.render(writer); 103 103 } 104 104 } 105 + 106 + test { 107 + std.testing.refAllDecls(@This()); 108 + }
+4 -4
flake.lock
··· 2 2 "nodes": { 3 3 "nixpkgs": { 4 4 "locked": { 5 - "lastModified": 1775710090, 6 - "narHash": "sha256-WGjBfvXv/mcg5yBg+AtK1Q3FHyXfjAAeJROmg7DLYfM=", 7 - "rev": "4c1018dae018162ec878d42fec712642d214fdfa", 5 + "lastModified": 1776169885, 6 + "narHash": "sha256-Gk2T0tDDDAs319hp/ak+bAIUG5bPMvnNEjPV8CS86Fg=", 7 + "rev": "4bd9165a9165d7b5e33ae57f3eecbcb28fb231c9", 8 8 "type": "tarball", 9 - "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre977467.4c1018dae018/nixexprs.tar.xz" 9 + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre980183.4bd9165a9165/nixexprs.tar.xz" 10 10 }, 11 11 "original": { 12 12 "type": "tarball",
+4
src/Cell.zig
··· 219 219 } 220 220 } 221 221 }; 222 + 223 + test { 224 + std.testing.refAllDecls(@This()); 225 + }
+4
src/GraphemeCache.zig
··· 18 18 // return the slice 19 19 return self.buf[self.idx .. self.idx + bytes.len]; 20 20 } 21 + 22 + test { 23 + std.testing.refAllDecls(@This()); 24 + }
+4
src/Image.zig
··· 186 186 .cols = cell_width, 187 187 }; 188 188 } 189 + 190 + test { 191 + std.testing.refAllDecls(@This()); 192 + }
+17 -13
src/InternalScreen.zig
··· 10 10 const InternalScreen = @This(); 11 11 12 12 pub const InternalCell = struct { 13 - char: std.ArrayListUnmanaged(u8) = .empty, 13 + char: std.ArrayList(u8) = .empty, 14 14 style: Style = .{}, 15 - uri: std.ArrayListUnmanaged(u8) = .empty, 16 - uri_id: std.ArrayListUnmanaged(u8) = .empty, 15 + uri: std.ArrayList(u8) = .empty, 16 + uri_id: std.ArrayList(u8) = .empty, 17 17 // if we got skipped because of a wide character 18 18 skipped: bool = false, 19 19 default: bool = true, ··· 48 48 mouse_shape: MouseShape = .default, 49 49 50 50 /// sets each cell to the default cell 51 - pub fn init(alloc: std.mem.Allocator, w: u16, h: u16) !InternalScreen { 52 - const arena = try alloc.create(std.heap.ArenaAllocator); 53 - arena.* = .init(alloc); 51 + pub fn init(gpa: std.mem.Allocator, w: u16, h: u16) !InternalScreen { 52 + const arena = try gpa.create(std.heap.ArenaAllocator); 53 + arena.* = .init(gpa); 54 54 var screen = InternalScreen{ 55 55 .arena = arena, 56 56 .buf = try arena.allocator().alloc(InternalCell, @as(usize, @intCast(w)) * h), 57 57 }; 58 58 for (screen.buf, 0..) |_, i| { 59 59 screen.buf[i] = .{ 60 - .char = try std.ArrayListUnmanaged(u8).initCapacity(arena.allocator(), 1), 60 + .char = try .initCapacity(arena.allocator(), 1), 61 61 .uri = .empty, 62 62 .uri_id = .empty, 63 63 }; ··· 92 92 const i = (@as(usize, @intCast(row)) * self.width) + col; 93 93 assert(i < self.buf.len); 94 94 self.buf[i].char.clearRetainingCapacity(); 95 - self.buf[i].char.appendSlice(self.arena.allocator(), cell.char.grapheme) catch { 96 - log.warn("couldn't write grapheme", .{}); 95 + self.buf[i].char.appendSlice(self.arena.allocator(), cell.char.grapheme) catch |err| { 96 + log.warn("couldn't write grapheme: {t}", .{err}); 97 97 }; 98 98 self.buf[i].uri.clearRetainingCapacity(); 99 - self.buf[i].uri.appendSlice(self.arena.allocator(), cell.link.uri) catch { 100 - log.warn("couldn't write uri", .{}); 99 + self.buf[i].uri.appendSlice(self.arena.allocator(), cell.link.uri) catch |err| { 100 + log.warn("couldn't write uri: {t}", .{err}); 101 101 }; 102 102 self.buf[i].uri_id.clearRetainingCapacity(); 103 - self.buf[i].uri_id.appendSlice(self.arena.allocator(), cell.link.params) catch { 104 - log.warn("couldn't write uri_id", .{}); 103 + self.buf[i].uri_id.appendSlice(self.arena.allocator(), cell.link.params) catch |err| { 104 + log.warn("couldn't write uri_id: {t}", .{err}); 105 105 }; 106 106 self.buf[i].style = cell.style; 107 107 self.buf[i].default = cell.default; ··· 143 143 try std.testing.expect(std.mem.eql(u8, read_back.char.grapheme, "A")); 144 144 try std.testing.expect(screen.readCell(2, 0) == null); 145 145 } 146 + 147 + test { 148 + std.testing.refAllDecls(@This()); 149 + }
+4
src/Key.zig
··· 456 456 test "name_map" { 457 457 try testing.expectEqual(insert, name_map.get("insert")); 458 458 } 459 + 460 + test { 461 + std.testing.refAllDecls(@This()); 462 + }
+5 -1
src/Loop.zig
··· 427 427 foo: u8, 428 428 }; 429 429 430 - var tty = try vaxis.Tty.init(&.{}); 430 + var tty = try vaxis.Tty.init(io, &.{}); 431 431 defer tty.deinit(); 432 432 433 433 var vx = try vaxis.init(io, std.testing.allocator, &env_map, .{}); ··· 442 442 try vx.enterAltScreen(tty.writer()); 443 443 try vx.queryTerminal(tty.writer(), .fromSeconds(1)); 444 444 } 445 + 446 + test { 447 + std.testing.refAllDecls(@This()); 448 + }
+5
src/Mouse.zig
··· 48 48 button: Button, 49 49 mods: Modifiers, 50 50 type: Type, 51 + 52 + test { 53 + const std = @import("std"); 54 + std.testing.refAllDecls(@This()); 55 + }
+4
src/Parser.zig
··· 1325 1325 try testing.expectEqual(7, result.n); 1326 1326 try testing.expectEqualDeep(expected_event, result.event); 1327 1327 } 1328 + 1329 + test { 1330 + std.testing.refAllDecls(@This()); 1331 + }
+4
src/Screen.zig
··· 72 72 test "refAllDecls" { 73 73 std.testing.refAllDecls(@This()); 74 74 } 75 + 76 + test { 77 + std.testing.refAllDecls(@This()); 78 + }
+5
src/ctlseqs.zig
··· 154 154 pub const osc12_query = "\x1b]12;?\x1b\\"; // cursor color 155 155 pub const osc12_set = "\x1b]12;rgb:{x:0>2}{x:0>2}/{x:0>2}{x:0>2}/{x:0>2}{x:0>2}\x1b\\"; // set terminal cursor color 156 156 pub const osc12_reset = "\x1b]112\x1b\\"; // reset cursor to terminal default 157 + 158 + test { 159 + const std = @import("std"); 160 + std.testing.refAllDecls(@This()); 161 + }
+5
src/event.zig
··· 28 28 cap_color_scheme_updates, 29 29 cap_multi_cursor, 30 30 }; 31 + 32 + test { 33 + const std = @import("std"); 34 + std.testing.refAllDecls(@This()); 35 + }
+4
src/gwidth.zig
··· 214 214 // Should be width 1 (combining mark is zero-width) 215 215 try testing.expectEqual(1, gwidth("á", .unicode)); 216 216 } 217 + 218 + test { 219 + std.testing.refAllDecls(@This()); 220 + }
+4
src/queue.zig
··· 370 370 try t1.await(io); 371 371 try t2.await(io); 372 372 } 373 + 374 + test { 375 + std.testing.refAllDecls(@This()); 376 + }
+5 -1
src/tty.zig
··· 707 707 tty_writer: *std.Io.Writer.Allocating, 708 708 709 709 /// Initializes a TestTty. 710 - pub fn init(buffer: []u8) !TestTty { 710 + pub fn init(_: std.Io, buffer: []u8) !TestTty { 711 711 _ = buffer; 712 712 713 713 if (builtin.os.tag != .linux) return error.SkipZigTest; ··· 761 761 return; 762 762 } 763 763 }; 764 + 765 + test { 766 + std.testing.refAllDecls(@This()); 767 + }
+4
src/unicode.zig
··· 63 63 pub fn graphemeIterator(str: []const u8) GraphemeIterator { 64 64 return GraphemeIterator.init(str); 65 65 } 66 + 67 + test { 68 + std.testing.refAllDecls(@This()); 69 + }
+4
src/vxfw/App.zig
··· 604 604 } 605 605 } 606 606 }; 607 + 608 + test { 609 + std.testing.refAllDecls(@This()); 610 + }
+1 -1
src/vxfw/Border.zig
··· 37 37 38 38 /// If Border has a bounded maximum size, it will shrink the maximum size to account for the border 39 39 /// before drawing the child. If the size is unbounded, border will draw the child and then itself 40 - /// around the childs size 40 + /// around the child's size 41 41 pub fn draw(self: *const Border, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 42 42 const max_width: ?u16 = if (ctx.max.width) |width| width -| 2 else null; 43 43 const max_height: ?u16 = if (ctx.max.height) |height| height -| 2 else null;
+5
typos.toml
··· 1 + [default] 2 + 3 + [default.extend-words] 4 + varius = "varius" 5 + Nam = "Nam"