diff --git a/build.zig b/build.zig index a2735ec..da52996 100644 --- a/build.zig +++ b/build.zig @@ -17,6 +17,13 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run unit tests"); const lint_step = b.step("lint", "Run lints"); + var version = std.ArrayList(u8).init(b.allocator); + defer version.deinit(); + gen_version(b, version.writer()) catch { + version.clearAndFree(); + version.appendSlice("unknown") catch {}; + }; + return (if (release) &build_release else &build_development)( b, run_step, @@ -29,6 +36,7 @@ pub fn build(b: *std.Build) void { use_llvm, pie, gui, + version.items, ); } @@ -44,6 +52,7 @@ fn build_development( use_llvm: ?bool, pie: ?bool, gui: bool, + version: []const u8, ) void { const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } }); const optimize = b.standardOptimizeOption(.{}); @@ -63,6 +72,7 @@ fn build_development( use_llvm, pie, gui, + version, ); } @@ -78,6 +88,7 @@ fn build_release( use_llvm: ?bool, pie: ?bool, _: bool, //gui + version: []const u8, ) void { const targets: []const std.Target.Query = &.{ .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, @@ -91,11 +102,8 @@ fn build_release( }; const optimize = .ReleaseFast; - var version = std.ArrayList(u8).init(b.allocator); - defer version.deinit(); - gen_version(b, version.writer()) catch unreachable; const write_file_step = b.addWriteFiles(); - const version_file = write_file_step.add("version", version.items); + const version_file = write_file_step.add("version", version); b.getInstallStep().dependOn(&b.addInstallFile(version_file, "version").step); for (targets) |t| { @@ -120,6 +128,7 @@ fn build_release( use_llvm, pie, false, //gui + version, ); if (t.os_tag == .windows) @@ -138,6 +147,7 @@ fn build_release( use_llvm, pie, true, //gui + version, ); } } @@ -157,6 +167,7 @@ pub fn build_exe( use_llvm: ?bool, pie: ?bool, gui: bool, + version: []const u8, ) void { const options = b.addOptions(); options.addOption(bool, "enable_tracy", tracy_enabled); @@ -183,7 +194,8 @@ pub fn build_exe( }; const wf = b.addWriteFiles(); - const version_info_file = wf.add("version", version_info.items); + const version_file = wf.add("version", version); + const version_info_file = wf.add("version_info", version_info.items); const vaxis_dep = b.dependency("vaxis", .{ .target = target, @@ -511,6 +523,7 @@ pub fn build_exe( exe.root_module.addImport("input", input_mod); exe.root_module.addImport("syntax", syntax_mod); exe.root_module.addImport("color", color_mod); + exe.root_module.addImport("version", b.createModule(.{ .root_source_file = version_file })); exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file })); if (target.result.os.tag == .windows) { @@ -553,6 +566,7 @@ pub fn build_exe( check_exe.root_module.addImport("input", input_mod); check_exe.root_module.addImport("syntax", syntax_mod); check_exe.root_module.addImport("color", color_mod); + check_exe.root_module.addImport("version", b.createModule(.{ .root_source_file = version_file })); check_exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file })); check_step.dependOn(&check_exe.step); diff --git a/src/main.zig b/src/main.zig index 65ce937..ffcb840 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const tui = @import("tui"); +const cbor = @import("cbor"); const thespian = @import("thespian"); const flags = @import("flags"); const builtin = @import("builtin"); @@ -15,6 +16,7 @@ const c = @cImport({ const build_options = @import("build_options"); const log = @import("log"); +pub const version = @embedFile("version"); pub const version_info = @embedFile("version_info"); pub var max_diff_lines: usize = 50000; @@ -303,7 +305,27 @@ pub fn main() anyerror!void { if (args.exec) |exec_str| { var cmds = std.mem.splitScalar(u8, exec_str, ';'); - while (cmds.next()) |cmd| try tui_proc.send(.{ "cmd", cmd, .{} }); + while (cmds.next()) |cmd| { + var count_args_ = std.mem.splitScalar(u8, cmd, ':'); + var count: usize = 0; + while (count_args_.next()) |_| count += 1; + if (count == 0) break; + + var msg = std.ArrayList(u8).init(a); + defer msg.deinit(); + const writer = msg.writer(); + + var cmd_args = std.mem.splitScalar(u8, cmd, ':'); + const cmd_ = cmd_args.next(); + try cbor.writeArrayHeader(writer, 3); + try cbor.writeValue(writer, "cmd"); + try cbor.writeValue(writer, cmd_); + try cbor.writeArrayHeader(writer, count - 1); + + while (cmd_args.next()) |arg| try cbor.writeValue(writer, arg); + + try tui_proc.send_raw(.{ .buf = msg.items }); + } } ctx.run(); @@ -347,7 +369,6 @@ fn trace_json(json: thespian.message.json_string_view) callconv(.C) void { extern fn ___tracy_emit_message(txt: [*]const u8, size: usize, callstack: c_int) void; fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.C) void { - const cbor = @import("cbor"); const State = struct { file: std.fs.File, last_time: i64, @@ -445,7 +466,6 @@ fn read_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs: *[][] } fn read_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void { - const cbor = @import("cbor"); var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }); defer file.close(); const text = try file.readToEndAlloc(allocator, 64 * 1024); @@ -481,7 +501,6 @@ fn read_text_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: } fn read_json_config_file(T: type, allocator: std.mem.Allocator, conf: *T, bufs_: *[][]const u8, file_name: []const u8) !void { - const cbor = @import("cbor"); var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }); defer file.close(); const json = try file.readToEndAlloc(allocator, 64 * 1024); @@ -502,7 +521,6 @@ fn read_cbor_config( file_name: []const u8, cb: []const u8, ) !void { - const cbor = @import("cbor"); var iter = cb; var field_name: []const u8 = undefined; while (cbor.matchString(&iter, &field_name) catch |e| switch (e) { @@ -613,7 +631,6 @@ fn config_eql(comptime T: type, a: T, b: T) bool { } fn write_json_file(comptime T: type, data: T, allocator: std.mem.Allocator, file_name: []const u8) !void { - const cbor = @import("cbor"); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true }); defer file.close(); diff --git a/src/syntax/src/file_types.zig b/src/syntax/src/file_types.zig index 870c6b7..69e7526 100644 --- a/src/syntax/src/file_types.zig +++ b/src/syntax/src/file_types.zig @@ -48,7 +48,7 @@ pub const conf = .{ .description = "Config", .color = 0x000000, .icon = "", - .extensions = .{ "conf", "config", ".gitconfig", "gui_config" }, + .extensions = .{ "conf", "log", "config", ".gitconfig", "gui_config" }, .highlights = fish.highlights, .comment = "#", .parser = fish.parser, diff --git a/src/tui/home.zig b/src/tui/home.zig index f90e7f9..60a9612 100644 --- a/src/tui/home.zig +++ b/src/tui/home.zig @@ -300,8 +300,15 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool { const x = @min(self.plane.dim_x() -| 32, 8); self.position_menu(self.v_center(5, self.menu_len, 5), self.center(x, self.menu_w)); } - const more = self.menu.render(theme); + self.plane.cursor_move_yx( + @intCast(self.plane.dim_y() - 2), + @intCast(@max(self.plane.dim_x(), root.version.len + 3) - root.version.len - 3), + ) catch {}; + self.plane.set_style_bg_transparent(style_subtext); + _ = self.plane.print("{s}", .{root.version}) catch return false; + + const more = self.menu.render(theme); return more or self.fire != null; }