diff --git a/build.zig b/build.zig index 7a108e6..e3b6d80 100644 --- a/build.zig +++ b/build.zig @@ -86,12 +86,14 @@ pub fn build_exe( strip: bool, pie: ?bool, ) void { - const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize }); - const ansi_term_dep = b.dependency("ansi-term", .{ .target = target, .optimize = optimize }); + const ansi_term_dep = b.dependency("ansi_term", .{ .target = target, .optimize = optimize }); const themes_dep = b.dependency("themes", .{}); const syntax_dep = b.dependency("syntax", .{ .target = target, .optimize = optimize }); - const thespian_dep = b.dependency("thespian", .{}); + const cbor_dep = syntax_dep.builder.dependency("cbor", .{ + .target = target, + .optimize = optimize, + }); const exe = b.addExecutable(.{ .name = "zat", @@ -105,8 +107,8 @@ pub fn build_exe( exe.root_module.addImport("theme", themes_dep.module("theme")); exe.root_module.addImport("themes", themes_dep.module("themes")); exe.root_module.addImport("clap", clap_dep.module("clap")); - exe.root_module.addImport("ansi-term", ansi_term_dep.module("ansi-term")); - exe.root_module.addImport("cbor", b.createModule(.{ .root_source_file = thespian_dep.path("src/cbor.zig") })); + exe.root_module.addImport("ansi_term", ansi_term_dep.module("ansi_term")); + exe.root_module.addImport("cbor", cbor_dep.module("cbor")); const exe_install = b.addInstallArtifact(exe, exe_install_options); b.getInstallStep().dependOn(&exe_install.step); diff --git a/build.zig.version b/build.zig.version index 54d1a4f..a803cc2 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.13.0 +0.14.0 diff --git a/build.zig.zon b/build.zig.zon index ffeae3c..42c83f1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,26 +1,23 @@ .{ - .name = "zat", + .name = .zat, .version = "1.0.0", + .fingerprint = 0x8da9db57fa011a09, .dependencies = .{ .clap = .{ - .url = "https://github.com/Hejsil/zig-clap/archive/c0193e9247335a6c1688b946325060289405de2a.tar.gz", - .hash = "12207ee987ce045596cb992cfb15b0d6d9456e50d4721c3061c69dabc2962053644d", + .url = "https://github.com/Hejsil/zig-clap/archive/0.10.0.tar.gz", + .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0", }, .themes = .{ - .url = "https://github.com/neurocyte/flow-themes/releases/download/master-618a7801d3383049adfe18cc09f5f5086c66995f/flow-themes.tar.gz", - .hash = "1220019ed92f48fb94d4ae82bba17b11d0ba06f17ed31cd66613b3c048b1d2382095", + .url = "https://github.com/neurocyte/flow-themes/releases/download/master-ac2e3fe2df3419b71276f86fa9c45fd39d668f23/flow-themes.tar.gz", + .hash = "N-V-__8AAEtaFwAjAHCmWHRCrBxL7uSG4hQiIsSgS32Y67K6", }, .syntax = .{ - .url = "https://github.com/neurocyte/flow-syntax/archive/28bc77f4615488aaa269c25fc862864f4b3a7460.tar.gz", - .hash = "1220abddc10ca8f8b6b5477f8c007948c168504b9dd3516899fe37251890eeabf4ab", + .url = "https://github.com/neurocyte/flow-syntax/archive/fa6a411bc769882acc87cf0d961af3813abf2eac.tar.gz", + .hash = "flow_syntax-0.1.0-X8jOof39AADK25RT1Bst_x7aUIwHbh7y09PJXBghLu_b", }, - .thespian = .{ - .url = "https://github.com/neurocyte/thespian/archive/d7dd27116398b17c8ab68327c384885f161d0cc1.tar.gz", - .hash = "1220ace715c2ee9087fe375996b8e9180bfc722b2d1acdcbf00e8b507b31dd1cdd94", - }, - .@"ansi-term" = .{ - .url = "https://github.com/ziglibs/ansi-term/archive/0bb62115db6749044765fdb37c9791388e7970f2.tar.gz", - .hash = "12200719196e0abd325efa248fb03882c8fa2c7130e3ae1d57dbff72afc846b28495", + .ansi_term = .{ + .url = "https://github.com/ziglibs/ansi-term/archive/c0e6ad093d4f6a9ed4e65d962d1e53b97888f989.tar.gz", + .hash = "ansi_term-0.1.0-_baAywpoAABEqsPmS5Jz_CddDCrG8qdIyRIESH8D2fzd", }, }, .paths = .{ diff --git a/scripts/fzf-grep b/scripts/fzf-grep index bc13fdc..a881787 100755 --- a/scripts/fzf-grep +++ b/scripts/fzf-grep @@ -15,4 +15,4 @@ rg \ --layout=reverse \ --ansi \ --tiebreak=index \ - --preview 'zat --highlight {2} --limit $FZF_PREVIEW_LINES {1}' + --preview 'zat --color --highlight {2} --limit $FZF_PREVIEW_LINES {1}' diff --git a/src/config_loader.zig b/src/config_loader.zig index 491970b..040e39b 100644 --- a/src/config_loader.zig +++ b/src/config_loader.zig @@ -31,7 +31,7 @@ fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]c var found = false; var field_name: []const u8 = undefined; if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidConfig; - inline for (@typeInfo(config).Struct.fields) |field_info| { + inline for (@typeInfo(config).@"struct".fields) |field_info| { if (std.mem.eql(u8, field_name, field_info.name)) { var value: field_info.type = undefined; if (!(try cbor.matchValue(&iter, cbor.extract(&value)))) return error.InvalidConfig; diff --git a/src/main.zig b/src/main.zig index 6b354ff..9d4668a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,7 +3,7 @@ const clap = @import("clap"); const syntax = @import("syntax"); const Theme = @import("theme"); const themes = @import("themes"); -const term = @import("ansi-term"); +const term = @import("ansi_term"); const config_loader = @import("config_loader.zig"); const Writer = std.io.BufferedWriter(4096, std.fs.File.Writer).Writer; @@ -70,7 +70,7 @@ pub fn main() !void { return list_langs(writer); if (res.args.color == 0 and !stdout_file.supportsAnsiEscapeCodes()) - return plain_cat(res.positionals); + return plain_cat(res.positionals[0]); var conf_buf: ?[]const u8 = null; const conf = config_loader.read_config(a, &conf_buf); @@ -106,8 +106,8 @@ pub fn main() !void { if (res.args.html != 0) try write_html_preamble(writer, theme.editor); - if (res.positionals.len > 0) { - for (res.positionals) |arg| { + if (res.positionals[0].len > 0) { + for (res.positionals[0]) |arg| { const file = if (std.mem.eql(u8, arg, "-")) std.io.getStdIn() else @@ -158,11 +158,11 @@ pub fn main() !void { try write_html_postamble(writer); } -fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8) *syntax { +fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8, query_cache: *syntax.QueryCache) *syntax { return (if (lang_override) |name| - syntax.create_file_type(a, name) catch unknown_file_type(name) + syntax.create_file_type(a, name, query_cache) catch unknown_file_type(name) else - syntax.create_guess_file_type(a, content, file_path)) catch syntax.create_file_type(a, lang_default) catch unknown_file_type(lang_default); + syntax.create_guess_file_type(a, content, file_path, query_cache)) catch syntax.create_file_type(a, lang_default, query_cache) catch unknown_file_type(lang_default); } fn unknown_file_type(name: []const u8) noreturn { @@ -200,7 +200,8 @@ fn render_file( end_line = start_line + lines; } - const parser = get_parser(a, content, file_path); + const query_cache = try syntax.QueryCache.create(a, .{}); + const parser = get_parser(a, content, file_path, query_cache); try parser.refresh_full(content); if (show) { try render_file_type(writer, parser.file_type, theme); @@ -399,16 +400,16 @@ fn list_themes(writer: Writer) !void { } fn set_ansi_style(writer: Writer, style: Theme.Style) Writer.Error!void { - const ansi_style = .{ + const ansi_style: term.style.Style = .{ .foreground = if (style.fg) |color| to_rgb_color(color.color) else .Default, .background = if (style.bg) |color| to_rgb_color(color.color) else .Default, .font_style = switch (style.fs orelse .normal) { .normal => term.style.FontStyle{}, - .bold => term.style.FontStyle.bold, - .italic => term.style.FontStyle.italic, - .underline => term.style.FontStyle.underline, - .undercurl => term.style.FontStyle.underline, - .strikethrough => term.style.FontStyle.crossedout, + .bold => term.style.FontStyle{ .bold = true }, + .italic => term.style.FontStyle{ .italic = true }, + .underline => term.style.FontStyle{ .underline = true }, + .undercurl => term.style.FontStyle{ .underline = true }, + .strikethrough => term.style.FontStyle{ .crossedout = true }, }, }; try term.format.updateStyle(writer, ansi_style, null); @@ -503,7 +504,7 @@ fn plain_cat_file(out_file: std.fs.File, in_file_name: []const u8) !void { try std.fs.cwd().openFile(in_file_name, .{}); defer in_file.close(); - var buf: [std.mem.page_size]u8 = undefined; + var buf: [std.heap.page_size_min]u8 = undefined; while (true) { const bytes_read = try in_file.read(&buf); if (bytes_read == 0) return;