this repo has no description
13
fork

Configure Feed

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

get fuzzy working and fix up previous examples

authored by

Jeffrey C. Ollie and committed by
Tim Culverhouse
b1a2c949 1c74bbb8

+38 -38
+2 -1
examples/counter.zig
··· 115 115 const io = init.io; 116 116 const allocator = init.gpa; 117 117 118 - var app = try vxfw.App.init(io, allocator, init.environ_map); 118 + var app: vxfw.App = undefined; 119 + try app.init(io, allocator, init.environ_map); 119 120 defer app.deinit(); 120 121 121 122 // We heap allocate our model because we will require a stable pointer to it in our Button
+26 -27
examples/fuzzy.zig
··· 11 11 12 12 /// Used for filtered RichText Spans and result 13 13 arena: std.heap.ArenaAllocator, 14 - filtered: std.ArrayList(vxfw.RichText), 15 14 result: []const u8, 16 15 17 16 pub fn init(gpa: std.mem.Allocator) !*Model { ··· 30 29 }, 31 30 }, 32 31 .text_field = .{ 33 - .buf = vxfw.TextField.Buffer.init(gpa), 32 + .buf = .init(gpa), 34 33 .userdata = model, 35 34 .onChange = Model.onChange, 36 35 .onSubmit = Model.onSubmit, 37 36 }, 38 37 .result = "", 39 - .arena = std.heap.ArenaAllocator.init(gpa), 38 + .arena = .init(gpa), 40 39 }; 41 40 42 41 return model; ··· 64 63 // Initialize the filtered list 65 64 const arena = self.arena.allocator(); 66 65 for (self.list.items) |line| { 67 - var spans = std.ArrayList(vxfw.RichText.TextSpan).empty; 66 + var spans: std.ArrayList(vxfw.RichText.TextSpan) = .empty; 68 67 const span: vxfw.RichText.TextSpan = .{ .text = line.text }; 69 68 try spans.append(arena, span); 70 69 try self.filtered.append(arena, .{ .text = spans.items }); ··· 201 200 return lower; 202 201 } 203 202 204 - pub fn main() !void { 205 - var debug_allocator = std.heap.GeneralPurposeAllocator(.{}){}; 206 - defer _ = debug_allocator.deinit(); 207 - 208 - const gpa = debug_allocator.allocator(); 203 + pub fn main(init: std.process.Init) !u8 { 204 + const io = init.io; 205 + const alloc = init.gpa; 209 206 210 - var app = try vxfw.App.init(gpa); 207 + var app: vxfw.App = undefined; 208 + try app.init(io, alloc, init.environ_map); 211 209 errdefer app.deinit(); 212 210 213 - const model = try Model.init(gpa); 214 - defer model.deinit(gpa); 211 + const model = try Model.init(alloc); 212 + defer model.deinit(alloc); 215 213 216 214 // Run the command 217 - var fd = std.process.Child.init(&.{"fd"}, gpa); 218 - fd.stdout_behavior = .Pipe; 219 - fd.stderr_behavior = .Pipe; 220 - var stdout = std.ArrayList(u8).empty; 221 - var stderr = std.ArrayList(u8).empty; 222 - defer stdout.deinit(gpa); 223 - defer stderr.deinit(gpa); 224 - try fd.spawn(); 225 - try fd.collectOutput(gpa, &stdout, &stderr, 10_000_000); 226 - _ = try fd.wait(); 215 + const fd = try std.process.run(alloc, io, .{ 216 + .argv = &.{"fd"}, 217 + }); 218 + defer alloc.free(fd.stdout); 219 + defer alloc.free(fd.stderr); 227 220 228 - var iter = std.mem.splitScalar(u8, stdout.items, '\n'); 221 + var iter = std.mem.splitScalar(u8, fd.stdout, '\n'); 229 222 while (iter.next()) |line| { 230 223 if (line.len == 0) continue; 231 - try model.list.append(gpa, .{ .text = line }); 224 + try model.list.append(alloc, .{ .text = line }); 232 225 } 233 226 234 227 try app.run(model.widget(), .{}); 235 228 app.deinit(); 236 229 237 230 if (model.result.len > 0) { 238 - _ = try std.posix.write(std.posix.STDOUT_FILENO, model.result); 239 - _ = try std.posix.write(std.posix.STDOUT_FILENO, "\n"); 231 + var stdout_file: std.Io.File = .stdout(); 232 + var buffer: [1024]u8 = undefined; 233 + var stdout_writer = stdout_file.writer(io, &buffer); 234 + const stdout = &stdout_writer.interface; 235 + try stdout.writeAll(model.result); 236 + try stdout.writeByte('\n'); 237 + try stdout.flush(); 238 + return 0; 240 239 } else { 241 - std.process.exit(130); 240 + return 130; 242 241 } 243 242 }
+4 -4
flake.lock
··· 26 26 ] 27 27 }, 28 28 "locked": { 29 - "lastModified": 1776053585, 30 - "narHash": "sha256-E06KRqtDxvKU3vxz7o7AgmeHVYIiIe5Q3kiFJQzEW4g=", 29 + "lastModified": 1776208985, 30 + "narHash": "sha256-IOuRFpbeQ9jSk54OURX5yvjoC759ujgSNjkMKpChdDA=", 31 31 "ref": "refs/heads/main", 32 - "rev": "a3ab4e8e3d22dbf9b4c0aff5f9c39e9a35ede6b6", 33 - "revCount": 1664, 32 + "rev": "e8ee348125247e7bd74932cc42ac92df90961d5b", 33 + "revCount": 1666, 34 34 "type": "git", 35 35 "url": "https://git.ocjtech.us/jeff/zig-overlay.git" 36 36 },
+3 -1
flake.nix
··· 32 32 default = pkgs.mkShell { 33 33 name = "libvaxis"; 34 34 nativeBuildInputs = [ 35 - zig.packages.${pkgs.stdenv.hostPlatform.system}.master 35 + pkgs.neovim 36 + pkgs.fd 37 + zig.packages.${pkgs.stdenv.hostPlatform.system}."0.16.0" 36 38 ]; 37 39 }; 38 40 });
+3 -5
src/vxfw/App.zig
··· 28 28 /// Create an application. We require stable pointers to do the set up, so this will create an App 29 29 /// object on the heap. Call destroy when the app is complete to reset terminal state and release 30 30 /// resources 31 - pub fn init(io: std.Io, allocator: Allocator, env_map: *std.process.Environ.Map) !App { 32 - var app: App = .{ 31 + pub fn init(self: *App, io: std.Io, allocator: Allocator, env_map: *std.process.Environ.Map) !void { 32 + self.* = .{ 33 33 .io = io, 34 34 .allocator = allocator, 35 - .tty = undefined, 35 + .tty = try vaxis.Tty.init(io, &self.buffer), 36 36 .vx = try vaxis.init(io, allocator, env_map, .{ 37 37 .system_clipboard_allocator = allocator, 38 38 .kitty_keyboard_flags = .{ ··· 43 43 .wants_focus = null, 44 44 .buffer = undefined, 45 45 }; 46 - app.tty = try vaxis.Tty.init(io, &app.buffer); 47 - return app; 48 46 } 49 47 50 48 pub fn deinit(self: *App) void {