From b2b34e471012935b15af3215814982d08e53e2fe Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 23 Nov 2025 21:45:51 +0100 Subject: [PATCH] build: update to libvaxis with uucode support --- build.zig | 2 +- build.zig.zon | 8 ++++++-- src/main.zig | 2 -- src/renderer/vaxis/Layer.zig | 9 +++------ src/renderer/vaxis/Plane.zig | 15 +++++++-------- src/renderer/vaxis/renderer.zig | 8 ++------ src/tui/tui.zig | 8 ++------ test/tests_buffer_input.txt | 2 -- test/tests_buffer_output.txt | 2 -- 9 files changed, 21 insertions(+), 35 deletions(-) diff --git a/build.zig b/build.zig index 1b3a01f..1ea58e4 100644 --- a/build.zig +++ b/build.zig @@ -324,7 +324,7 @@ pub fn build_exe( .root_source_file = b.path("src/tracy_noop.zig"), }); - const zg_dep = vaxis_dep.builder.dependency("zg", .{ + const zg_dep = b.dependency("zg", .{ .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon index 4b63ca8..275921a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -30,8 +30,8 @@ .hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D", }, .vaxis = .{ - .url = "git+https://github.com/neurocyte/libvaxis?ref=main#57a4662955bc70ee13248e8c209ff7db13aeeb55", - .hash = "vaxis-0.5.1-BWNV_IQjCQDoLX03Eb2iQTBYqReabnFPAq5cZROLqNdJ", + .url = "git+https://github.com/neurocyte/libvaxis?ref=main#e9c1111efd98aeb7c2db45d3e31987429fb5f26d", + .hash = "vaxis-0.5.1-BWNV_BkyCQAo2UBeY_gbzP09d4pHDaqtg44snF5k3mh2", }, .zeit = .{ .url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88", @@ -42,6 +42,10 @@ .hash = "zigwin32-25.0.28-preview-AAAAAICM5AMResOGQnQ85mfe60TTOQeMtt7GRATUOKoP", .lazy = true, }, + .zg = .{ + .url = "git+https://codeberg.org/neurocyte/zg?ref=master#cdcab8b9ea3458efd710008055d993c5dbdb1af7", + .hash = "zg-0.15.2-oGqU3AtAtAI7gs7zPvzg2_TlVIqi9wCNEw7DLvD5OvDN", + }, }, .paths = .{ "include", diff --git a/src/main.zig b/src/main.zig index 32aa1ef..7e30ebe 100644 --- a/src/main.zig +++ b/src/main.zig @@ -50,8 +50,6 @@ pub fn main() anyerror!void { } const a = std.heap.c_allocator; - const letter_casing = @import("Buffer").unicode.get_letter_casing(); - _ = letter_casing; // no need to free letter_casing as it is globally static const Flags = struct { pub const description = diff --git a/src/renderer/vaxis/Layer.zig b/src/renderer/vaxis/Layer.zig index f43d827..48ecaec 100644 --- a/src/renderer/vaxis/Layer.zig +++ b/src/renderer/vaxis/Layer.zig @@ -13,14 +13,13 @@ plane_: Plane, const View = struct { allocator: std.mem.Allocator, screen: vaxis.Screen, - unicode: *const vaxis.Unicode, pub const Config = struct { h: u16, w: u16, }; - pub fn init(allocator: std.mem.Allocator, unicode: *const vaxis.Unicode, config: Config) std.mem.Allocator.Error!View { + pub fn init(allocator: std.mem.Allocator, config: Config) std.mem.Allocator.Error!View { return .{ .allocator = allocator, .screen = try vaxis.Screen.init(allocator, .{ @@ -29,7 +28,6 @@ const View = struct { .x_pixel = 0, .y_pixel = 0, }), - .unicode = unicode, }; } @@ -45,10 +43,10 @@ pub const Options = struct { w: u16 = 0, }; -pub fn init(allocator: std.mem.Allocator, unicode: *const vaxis.Unicode, opts: Options) std.mem.Allocator.Error!*Layer { +pub fn init(allocator: std.mem.Allocator, opts: Options) std.mem.Allocator.Error!*Layer { const self = try allocator.create(Layer); self.* = .{ - .view = try View.init(allocator, unicode, .{ + .view = try View.init(allocator, .{ .h = opts.h, .w = opts.w, }), @@ -81,7 +79,6 @@ fn window(self: *Layer) vaxis.Window { .width = self.view.screen.width, .height = self.view.screen.height, .screen = &self.view.screen, - .unicode = self.view.unicode, }; } diff --git a/src/renderer/vaxis/Plane.zig b/src/renderer/vaxis/Plane.zig index 2a7aedf..b59b1f6 100644 --- a/src/renderer/vaxis/Plane.zig +++ b/src/renderer/vaxis/Plane.zig @@ -181,7 +181,7 @@ pub fn putstr(self: *Plane, text: []const u8) !usize { var result: usize = 0; const height = self.window.height; const width = self.window.width; - var iter = self.window.unicode.graphemeIterator(text); + var iter = vaxis.unicode.graphemeIterator(text); while (iter.next()) |grapheme| { const s = grapheme.bytes(text); if (std.mem.eql(u8, s, "\n")) { @@ -207,7 +207,7 @@ pub fn putstr(self: *Plane, text: []const u8) !usize { pub fn putstr_unicode(self: *Plane, text: []const u8) !usize { var result: usize = 0; - var iter = self.window.unicode.graphemeIterator(text); + var iter = vaxis.unicode.graphemeIterator(text); while (iter.next()) |grapheme| { const s_ = grapheme.bytes(text); const s = switch (s_[0]) { @@ -443,7 +443,7 @@ pub fn egc_length(self: *const Plane, egcs: []const u8, colcount: *c_int, abs_co colcount.* = @intCast(tab_width - (abs_col % tab_width)); return 1; } - var iter = self.window.unicode.graphemeIterator(egcs); + var iter = vaxis.unicode.graphemeIterator(egcs); const grapheme = iter.next() orelse { colcount.* = 1; return 1; @@ -469,8 +469,8 @@ pub fn egc_chunk_width(self: *const Plane, chunk_: []const u8, abs_col_: usize, return colcount; } -pub fn egc_last(self: *const Plane, egcs: []const u8) []const u8 { - var iter = self.window.unicode.graphemeIterator(egcs); +pub fn egc_last(egcs: []const u8) []const u8 { + var iter = vaxis.unicode.graphemeIterator(egcs); var last: []const u8 = egcs[0..0]; while (iter.next()) |grapheme| last = grapheme.bytes(egcs); return last; @@ -493,9 +493,8 @@ pub fn metrics(self: *const Plane, tab_width: usize) Buffer.Metrics { }.f, .tab_width = tab_width, .egc_last = struct { - fn f(self_: Buffer.Metrics, egcs: []const u8) []const u8 { - const plane: *const Plane = @ptrCast(@alignCast(self_.ctx)); - return plane.egc_last(egcs); + fn f(_: Buffer.Metrics, egcs: []const u8) []const u8 { + return egc_last(egcs); } }.f, }; diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index b71767c..30a9252 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -683,18 +683,14 @@ const Loop = struct { fn ttyRun(self: *Loop) !void { switch (builtin.os.tag) { .windows => { - var parser: vaxis.Parser = .{ - .grapheme_data = &self.vaxis.unicode.width_data.graphemes, - }; + var parser: vaxis.Parser = .{}; const a = self.vaxis.opts.system_clipboard_allocator orelse @panic("no tty allocator"); while (!self.should_quit) { self.postEvent(try self.tty.nextEvent(&parser, a)); } }, else => { - var parser: vaxis.Parser = .{ - .grapheme_data = &self.vaxis.unicode.width_data.graphemes, - }; + var parser: vaxis.Parser = .{}; const a = self.vaxis.opts.system_clipboard_allocator orelse @panic("no tty allocator"); diff --git a/src/tui/tui.zig b/src/tui/tui.zig index fe7c1bf..34ce1d4 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -1606,11 +1606,7 @@ fn stdplane(self: *Self) renderer.Plane { pub fn top_layer(opts: renderer.Layer.Options) ?*renderer.Plane { const self = current(); if (self.top_layer_) |_| return null; - self.top_layer_ = renderer.Layer.init( - self.allocator, - self.rdr_.stdplane().window.unicode, - opts, - ) catch @panic("OOM toplayer"); + self.top_layer_ = renderer.Layer.init(self.allocator, opts) catch @panic("OOM toplayer"); return self.top_layer_.?.plane(); } @@ -1626,7 +1622,7 @@ pub fn egc_chunk_width(chunk: []const u8, abs_col: usize, tab_width: usize) usiz } pub fn egc_last(egcs: []const u8) []const u8 { - return plane().egc_last(egcs); + return renderer.Plane.egc_last(egcs); } pub fn screen() Widget.Box { diff --git a/test/tests_buffer_input.txt b/test/tests_buffer_input.txt index 7b19189..1c4f2fe 100644 --- a/test/tests_buffer_input.txt +++ b/test/tests_buffer_input.txt @@ -50,8 +50,6 @@ pub fn main() anyerror!void { } const a = std.heap.c_allocator; - const letter_casing = @import("Buffer").unicode.get_letter_casing(); - _ = letter_casing; // no need to free letter_casing as it is globally static const Flags = struct { pub const description = diff --git a/test/tests_buffer_output.txt b/test/tests_buffer_output.txt index 7b19189..1c4f2fe 100644 --- a/test/tests_buffer_output.txt +++ b/test/tests_buffer_output.txt @@ -50,8 +50,6 @@ pub fn main() anyerror!void { } const a = std.heap.c_allocator; - const letter_casing = @import("Buffer").unicode.get_letter_casing(); - _ = letter_casing; // no need to free letter_casing as it is globally static const Flags = struct { pub const description =