From 2338489da3e365154f7832a53239d0909e173675 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 4 Jun 2024 22:24:03 +0200 Subject: [PATCH] build: update to latest zig and libvaxis and remove notcurses dependency --- .gitignore | 2 +- build.zig | 71 ++++++++++++++------------------- build.zig.version | 2 +- build.zig.zon | 42 +++++++++---------- src/project_manager.zig | 1 + src/renderer/vaxis/renderer.zig | 34 ++++++++-------- src/ripgrep.zig | 8 ++-- 7 files changed, 74 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index 46ea169..278aa08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.cache/ /zig-out/ -/zig-cache/ +/.zig-cache/ diff --git a/build.zig b/build.zig index e5c8661..97994b1 100644 --- a/build.zig +++ b/build.zig @@ -21,8 +21,6 @@ pub fn build(b: *std.Build) void { const optimize_deps_option = b.option(bool, "optimize_deps", "Enable optimization for dependecies (default: yes)"); const use_llvm_option = b.option(bool, "use_llvm", "Enable llvm backend (default: yes)"); const use_lld_option = b.option(bool, "use_lld", "Enable lld backend (default: yes)"); - const use_system_notcurses = b.option(bool, "use_system_notcurses", "Build against system notcurses (default: no)") orelse false; - const use_vaxis = b.option(bool, "use_vaxis", "Enable libvaxis rendering backend (default: no)") orelse false; const tracy_enabled = if (enable_tracy_option) |enabled| enabled else false; const optimize_deps_enabled = if (optimize_deps_option) |enabled| enabled else true; @@ -32,8 +30,6 @@ pub fn build(b: *std.Build) void { options.addOption(bool, "optimize_deps", optimize_deps_enabled); options.addOption(bool, "use_llvm", use_llvm_option orelse false); options.addOption(bool, "use_lld", use_lld_option orelse false); - options.addOption(bool, "use_system_notcurses", use_system_notcurses); - options.addOption(bool, "use_vaxis", use_vaxis); const options_mod = options.createModule(); @@ -52,16 +48,13 @@ pub fn build(b: *std.Build) void { else => std.debug.panic("makeDir(\".cache/cdb\") failed: {any}", .{e}), }; - const notcurses_dep = b.dependency("notcurses", .{ - .target = target, - .optimize = dependency_optimize, - .use_system_notcurses = use_system_notcurses, - }); - const notcurses_mod = notcurses_dep.module("notcurses"); - const vaxis_dep = b.dependency("vaxis", .{ .target = target, .optimize = dependency_optimize, + .use_libxev = false, + .use_zigimg = false, + .use_znvim = false, + .use_gap_buffer = false, }); const vaxis_mod = vaxis_dep.module("vaxis"); @@ -85,7 +78,7 @@ pub fn build(b: *std.Build) void { .optimize = dependency_optimize, }) else undefined; const tracy_mod = if (tracy_enabled) tracy_dep.module("tracy") else b.createModule(.{ - .root_source_file = .{ .path = "src/tracy_noop.zig" }, + .root_source_file = b.path("src/tracy_noop.zig"), }); const zg_dep = b.dependency("zg", .{ @@ -110,39 +103,29 @@ pub fn build(b: *std.Build) void { const cbor_mod = thespian_dep.module("cbor"); const help_mod = b.createModule(.{ - .root_source_file = .{ .path = "help.md" }, + .root_source_file = b.path("help.md"), }); const config_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/config.zig" }, + .root_source_file = b.path("src/config.zig"), .imports = &.{ .{ .name = "cbor", .module = cbor_mod }, }, }); const log_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/log.zig" }, + .root_source_file = b.path("src/log.zig"), .imports = &.{ .{ .name = "thespian", .module = thespian_mod }, }, }); const color_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/color.zig" }, + .root_source_file = b.path("src/color.zig"), }); - const notcurses_renderer_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/renderer/notcurses/renderer.zig" }, - .imports = &.{ - .{ .name = "notcurses", .module = notcurses_mod }, - .{ .name = "theme", .module = themes_dep.module("theme") }, - .{ .name = "cbor", .module = cbor_mod }, - .{ .name = "log", .module = log_mod }, - }, - }); - - const vaxis_renderer_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/renderer/vaxis/renderer.zig" }, + const renderer_mod = b.createModule(.{ + .root_source_file = b.path("src/renderer/vaxis/renderer.zig"), .imports = &.{ .{ .name = "vaxis", .module = vaxis_mod }, .{ .name = "theme", .module = themes_dep.module("theme") }, @@ -151,10 +134,8 @@ pub fn build(b: *std.Build) void { }, }); - const renderer_mod = if (use_vaxis) vaxis_renderer_mod else notcurses_renderer_mod; - const Buffer_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/buffer/Buffer.zig" }, + .root_source_file = b.path("src/buffer/Buffer.zig"), .imports = &.{ .{ .name = "renderer", .module = renderer_mod }, .{ .name = "cbor", .module = cbor_mod }, @@ -162,7 +143,7 @@ pub fn build(b: *std.Build) void { }); const ripgrep_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/ripgrep.zig" }, + .root_source_file = b.path("src/ripgrep.zig"), .imports = &.{ .{ .name = "thespian", .module = thespian_mod }, .{ .name = "cbor", .module = cbor_mod }, @@ -171,14 +152,14 @@ pub fn build(b: *std.Build) void { }); const location_history_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/location_history.zig" }, + .root_source_file = b.path("src/location_history.zig"), .imports = &.{ .{ .name = "thespian", .module = thespian_mod }, }, }); const project_manager_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/project_manager.zig" }, + .root_source_file = b.path("src/project_manager.zig"), .imports = &.{ .{ .name = "log", .module = log_mod }, .{ .name = "cbor", .module = cbor_mod }, @@ -192,7 +173,7 @@ pub fn build(b: *std.Build) void { }); const diff_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/diff.zig" }, + .root_source_file = b.path("src/diff.zig"), .imports = &.{ .{ .name = "thespian", .module = thespian_mod }, .{ .name = "Buffer", .module = Buffer_mod }, @@ -204,12 +185,12 @@ pub fn build(b: *std.Build) void { }); const text_manip_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/text_manip.zig" }, + .root_source_file = b.path("src/text_manip.zig"), .imports = &.{}, }); const tui_mod = b.createModule(.{ - .root_source_file = .{ .path = "src/tui/tui.zig" }, + .root_source_file = b.path("src/tui/tui.zig"), .imports = &.{ .{ .name = "renderer", .module = renderer_mod }, .{ .name = "thespian", .module = thespian_mod }, @@ -235,7 +216,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "flow", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -264,7 +245,7 @@ pub fn build(b: *std.Build) void { const check_exe = b.addExecutable(.{ .name = "flow", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -284,7 +265,7 @@ pub fn build(b: *std.Build) void { check.dependOn(&check_exe.step); const tests = b.addTest(.{ - .root_source_file = .{ .path = "test/tests.zig" }, + .root_source_file = b.path("test/tests.zig"), .target = target, .optimize = optimize, }); @@ -299,4 +280,14 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&test_run_cmd.step); + + const lints_step = b.step("lint", "Run lints"); + + const lints = b.addFmt(.{ + .paths = &.{ "src", "test", "build.zig" }, + .check = true, + }); + + lints_step.dependOn(&lints.step); + b.default_step.dependOn(lints_step); } diff --git a/build.zig.version b/build.zig.version index ac454c6..3d2dcc1 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.12.0 +0.13.0-dev.363+7fc3fb955 diff --git a/build.zig.zon b/build.zig.zon index 52f317e..608b8bc 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,47 +1,43 @@ .{ .name = "flow", - .version = "0.0.1", + .version = "0.1.0", .dependencies = .{ - .notcurses = .{ - .url = "https://github.com/neurocyte/notcurses-zig/archive/b22c7f04e4fca9d36247a9e867eb4f3f9ccf914a.tar.gz", - .hash = "12200a3fa3e5d76f1ff96d1ca5fab64b61ff0e3f28f953ac8464f43986ca7cf4f7eb", - }, .clap = .{ - .url = "https://github.com/Hejsil/zig-clap/archive/8c98e6404b22aafc0184e999d8f068b81cc22fa1.tar.gz", - .hash = "122014e73fd712190e109950837b97f6143f02d7e2b6986e1db70b6f4aadb5ba6a0d", + .url = "https://github.com/Hejsil/zig-clap/archive/60cd46aacff4960104703da9ba683077b1e3c76c.tar.gz", + .hash = "12205eb22c644df2469045083efe9c92189d56494ebe8901b36ef1218c3717e6eb78", }, .tracy = .{ - .url = "https://github.com/neurocyte/zig-tracy/archive/303574aa9015b2c5e80e053234b3ec1d6227f0ed.tar.gz", - .hash = "12209136682cc51f20f5a4ff2365ca1a13445688aadfc570c4684b828bf9e48d2011", + .url = "https://github.com/neurocyte/zig-tracy/archive/58999b786089e5319dd0707f6afbfca04c6340e7.tar.gz", + .hash = "1220a2c8f8db1b5265458ac967ea1f7cc0a8ddcd1d774df3b73d86c4f529aadbfb94", }, .dizzy = .{ - .url = "https://github.com/SuperAuguste/dizzy/archive/d4aaf67d0f5ef69d0a0287ae472ddfece064d341.tar.gz", - .hash = "1220a7cf5f59b61257993bc5b02991ffc523d103f66842fa8d8ab5c9fdba52799340", + .url = "https://github.com/neurocyte/dizzy/archive/455d18369cbb2a0458ba70be919cd378338d695e.tar.gz", + .hash = "1220220dbc7fe91c1c54438193ca765cebbcb7d58f35cdcaee404a9d2245a42a4362", }, .thespian = .{ - .url = "https://github.com/neurocyte/thespian/archive/a98cb1f5e62a1e0ea8cdf2c8550ad3a7de87370c.tar.gz", - .hash = "1220c8ff98a15efe5a187adc2dc8c24a35664417c8b1232cb0a02f2412212ffea374", + .url = "https://github.com/neurocyte/thespian/archive/3121af2ec484841103eae059c79e4c3ddbec4149.tar.gz", + .hash = "1220794a8ca2f5e93e8dad61338f3bfd7a322f0c85635f367bc6cf0c178dcde70247", }, .themes = .{ - .url = "https://github.com/neurocyte/flow-themes/releases/download/master-68a95a4984088ec8480252af93f3069f25f21b66/flow-themes.tar.gz", - .hash = "122016a42d46713954340e55981a9102b209c838b855895842d71ad6aebd2d07a58d", + .url = "https://github.com/neurocyte/flow-themes/releases/download/master-15e8cad1619429bf2547a6819b5b999510d5c1e5/flow-themes.tar.gz", + .hash = "1220906d82deb37573207c5d365edb6b58a0b1b3e4ef68902019a23a0eb5e5a34298", }, .syntax = .{ - .url = "https://github.com/neurocyte/flow-syntax/archive/9ed377279e0723f53e0063f0577fbe17d2f7bd73.tar.gz", - .hash = "12208577d504d28012c810f5defb8f8086f46a76203020bccad33925c5b9750fd0a8", + .url = "https://github.com/neurocyte/flow-syntax/archive/10a9a8598b837ab1dd5b7adcba8e3a4ed4358983.tar.gz", + .hash = "12207c2b9285958b388e331a8d1f6066b92b30d3dc4d548b1f1d04e7e03c79f8c3c3", }, .fuzzig = .{ - .url = "https://github.com/fjebaker/fuzzig/archive/c6a0e0ca1a24e55ebdce51c83b918d4325ca7032.tar.gz", - .hash = "1220214dfb9a0806d9c8a059beb9e3b07811fd138cd5baeb9d1da432588920a084bf", + .url = "https://github.com/fjebaker/fuzzig/archive/0fd156d5097365151e85a85eef9d8cf0eebe7b00.tar.gz", + .hash = "122019f077d09686b1ec47928ca2b4bf264422f3a27afc5b49dafb0129a4ceca0d01", }, .vaxis = .{ - .url = "https://github.com/rockorager/libvaxis/archive/93ac8e00f880e50007d6cf049df28e44b7de889c.tar.gz", - .hash = "1220033e2f7770acacae66f5ba02d689f025f325b0352316e48142f0a61d352b98aa", + .url = "https://github.com/rockorager/libvaxis/archive/f41b4dcc0718e4c3c95db6d1f4ac0193382b767c.tar.gz", + .hash = "122003a9b987a0b77bbad2ea2c396b570646faa165f73503391d7419fbb935fcc363", }, .zg = .{ - .url = "git+https://codeberg.org/dude_the_builder/zg#16735685fcc3410de361ba3411788ad1fb4fe188", - .hash = "1220fe9ac5cdb41833d327a78745614e67d472469f8666567bd8cf9f5847a52b1c51", + .url = "git+https://codeberg.org/dude_the_builder/zg#c425c9c8511bf92e14b8b612d1d16e774b186f2e", + .hash = "1220c79009f1e443b015db4de6e5319432538ead2fea10d271f3f35d3ae83c996789", }, }, .paths = .{ diff --git a/src/project_manager.zig b/src/project_manager.zig index 08831f9..be755e2 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -464,6 +464,7 @@ const filtered_dirs = [_][]const u8{ ".var", "zig-out", "zig-cache", + ".zig-cache", ".rustup", ".npm", ".cargo", diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 9f7f330..e37b62d 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -21,6 +21,7 @@ pub const log_name = "vaxis"; a: std.mem.Allocator, +tty: vaxis.Tty, vx: vaxis.Vaxis, no_alternate: bool, @@ -58,6 +59,7 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) ! }; return .{ .a = a, + .tty = try vaxis.Tty.init(), .vx = try vaxis.init(a, opts), .no_alternate = no_alternate, .event_buffer = std.ArrayList(u8).init(a), @@ -70,7 +72,8 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) ! pub fn deinit(self: *Self) void { panic_cleanup_tty = null; - self.vx.deinit(self.a); + self.vx.deinit(self.a, self.tty.anyWriter()); + self.tty.deinit(); self.bracketed_paste_buffer.deinit(); self.input_buffer.deinit(); self.event_buffer.deinit(); @@ -85,25 +88,22 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_ pub fn run(self: *Self) !void { self.vx.sgr = .legacy; - if (self.vx.tty == null) { - self.vx.tty = try vaxis.Tty.init(); - panic_cleanup_tty = &(self.vx.tty.?); - } - if (!self.no_alternate) try self.vx.enterAltScreen(); - try self.vx.queryTerminalSend(); + panic_cleanup_tty = &self.tty; + if (!self.no_alternate) try self.vx.enterAltScreen(self.tty.anyWriter()); + try self.vx.queryTerminalSend(self.tty.anyWriter()); const ws = try vaxis.Tty.getWinsize(self.input_fd_blocking()); - try self.vx.resize(self.a, ws); + try self.vx.resize(self.a, self.tty.anyWriter(), ws); self.vx.queueRefresh(); - try self.vx.setBracketedPaste(true); + try self.vx.setBracketedPaste(self.tty.anyWriter(), true); } pub fn render(self: *Self) !void { - return self.vx.render(); + return self.vx.render(self.tty.anyWriter()); } pub fn refresh(self: *Self) !void { const ws = try vaxis.Tty.getWinsize(self.input_fd_blocking()); - try self.vx.resize(self.a, ws); + try self.vx.resize(self.a, self.tty.anyWriter(), ws); self.vx.queueRefresh(); } @@ -123,7 +123,7 @@ pub fn stdplane(self: *Self) Plane { } pub fn input_fd_blocking(self: Self) i32 { - return self.vx.tty.?.fd; + return self.tty.fd; } pub fn leave_alternate_screen(self: *Self) void { @@ -251,8 +251,8 @@ pub fn process_input(self: *Self, input_: []const u8) !void { self.vx.caps.sgr_pixels = true; }, .cap_da1 => { - self.vx.enableDetectedFeatures() catch |e| self.logger.err("enable features", e); - try self.vx.setMouseMode(true); + self.vx.enableDetectedFeatures(self.tty.anyWriter()) catch |e| self.logger.err("enable features", e); + try self.vx.setMouseMode(self.tty.anyWriter(), true); }, .cap_kitty_keyboard => { self.logger.print("kitty keyboard capability detected", .{}); @@ -306,15 +306,15 @@ fn handle_bracketed_paste_end(self: *Self) !void { } pub fn set_terminal_title(self: *Self, text: []const u8) void { - self.vx.setTitle(text) catch {}; + self.vx.setTitle(self.tty.anyWriter(), text) catch {}; } pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void { - self.vx.copyToSystemClipboard(text, self.a) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e); + self.vx.copyToSystemClipboard(self.tty.anyWriter(), text, self.a) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e); } pub fn request_system_clipboard(self: *Self) void { - self.vx.requestSystemClipboard() catch |e| log.logger(log_name).err("request_system_clipboard", e); + self.vx.requestSystemClipboard(self.tty.anyWriter()) catch |e| log.logger(log_name).err("request_system_clipboard", e); } pub fn request_mouse_cursor_text(self: *Self, push_or_pop: bool) void { diff --git a/src/ripgrep.zig b/src/ripgrep.zig index fb16e96..7c13415 100644 --- a/src/ripgrep.zig +++ b/src/ripgrep.zig @@ -6,7 +6,7 @@ const log = @import("log"); pub const ripgrep_binary = "rg"; pid: ?tp.pid, -stdin_behavior: std.ChildProcess.StdIo, +stdin_behavior: std.process.Child.StdIo, const Self = @This(); const module_name = @typeName(Self); @@ -25,7 +25,7 @@ pub fn find_in_files(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) return create(a, query, tag, .Close); } -fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.ChildProcess.StdIo) Error!Self { +fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) Error!Self { return .{ .pid = try Process.create(a, query, tag, stdin_behavior), .stdin_behavior = stdin_behavior }; } @@ -79,11 +79,11 @@ const Process = struct { parent: tp.pid, tag: [:0]const u8, logger: log.Logger, - stdin_behavior: std.ChildProcess.StdIo, + stdin_behavior: std.process.Child.StdIo, const Receiver = tp.Receiver(*Process); - pub fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.ChildProcess.StdIo) Error!tp.pid { + pub fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) Error!tp.pid { const self = try a.create(Process); self.* = .{ .a = a,