Compare commits

...

3 commits

4 changed files with 51 additions and 13 deletions

View file

@ -17,6 +17,13 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Run unit tests"); const test_step = b.step("test", "Run unit tests");
const lint_step = b.step("lint", "Run lints"); 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)( return (if (release) &build_release else &build_development)(
b, b,
run_step, run_step,
@ -29,6 +36,7 @@ pub fn build(b: *std.Build) void {
use_llvm, use_llvm,
pie, pie,
gui, gui,
version.items,
); );
} }
@ -44,6 +52,7 @@ fn build_development(
use_llvm: ?bool, use_llvm: ?bool,
pie: ?bool, pie: ?bool,
gui: bool, gui: bool,
version: []const u8,
) void { ) void {
const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } }); const target = b.standardTargetOptions(.{ .default_target = .{ .abi = if (builtin.os.tag == .linux and !tracy_enabled) .musl else null } });
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
@ -63,6 +72,7 @@ fn build_development(
use_llvm, use_llvm,
pie, pie,
gui, gui,
version,
); );
} }
@ -78,6 +88,7 @@ fn build_release(
use_llvm: ?bool, use_llvm: ?bool,
pie: ?bool, pie: ?bool,
_: bool, //gui _: bool, //gui
version: []const u8,
) void { ) void {
const targets: []const std.Target.Query = &.{ const targets: []const std.Target.Query = &.{
.{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .musl },
@ -91,11 +102,8 @@ fn build_release(
}; };
const optimize = .ReleaseFast; 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 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); b.getInstallStep().dependOn(&b.addInstallFile(version_file, "version").step);
for (targets) |t| { for (targets) |t| {
@ -120,6 +128,7 @@ fn build_release(
use_llvm, use_llvm,
pie, pie,
false, //gui false, //gui
version,
); );
if (t.os_tag == .windows) if (t.os_tag == .windows)
@ -138,6 +147,7 @@ fn build_release(
use_llvm, use_llvm,
pie, pie,
true, //gui true, //gui
version,
); );
} }
} }
@ -157,6 +167,7 @@ pub fn build_exe(
use_llvm: ?bool, use_llvm: ?bool,
pie: ?bool, pie: ?bool,
gui: bool, gui: bool,
version: []const u8,
) void { ) void {
const options = b.addOptions(); const options = b.addOptions();
options.addOption(bool, "enable_tracy", tracy_enabled); options.addOption(bool, "enable_tracy", tracy_enabled);
@ -183,7 +194,8 @@ pub fn build_exe(
}; };
const wf = b.addWriteFiles(); 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", .{ const vaxis_dep = b.dependency("vaxis", .{
.target = target, .target = target,
@ -511,6 +523,7 @@ pub fn build_exe(
exe.root_module.addImport("input", input_mod); exe.root_module.addImport("input", input_mod);
exe.root_module.addImport("syntax", syntax_mod); exe.root_module.addImport("syntax", syntax_mod);
exe.root_module.addImport("color", color_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 })); exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file }));
if (target.result.os.tag == .windows) { 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("input", input_mod);
check_exe.root_module.addImport("syntax", syntax_mod); check_exe.root_module.addImport("syntax", syntax_mod);
check_exe.root_module.addImport("color", color_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_exe.root_module.addImport("version_info", b.createModule(.{ .root_source_file = version_info_file }));
check_step.dependOn(&check_exe.step); check_step.dependOn(&check_exe.step);

View file

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const tui = @import("tui"); const tui = @import("tui");
const cbor = @import("cbor");
const thespian = @import("thespian"); const thespian = @import("thespian");
const flags = @import("flags"); const flags = @import("flags");
const builtin = @import("builtin"); const builtin = @import("builtin");
@ -15,6 +16,7 @@ const c = @cImport({
const build_options = @import("build_options"); const build_options = @import("build_options");
const log = @import("log"); const log = @import("log");
pub const version = @embedFile("version");
pub const version_info = @embedFile("version_info"); pub const version_info = @embedFile("version_info");
pub var max_diff_lines: usize = 50000; pub var max_diff_lines: usize = 50000;
@ -303,7 +305,27 @@ pub fn main() anyerror!void {
if (args.exec) |exec_str| { if (args.exec) |exec_str| {
var cmds = std.mem.splitScalar(u8, 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(); 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; 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 { fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.C) void {
const cbor = @import("cbor");
const State = struct { const State = struct {
file: std.fs.File, file: std.fs.File,
last_time: i64, 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 { 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 }); var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only });
defer file.close(); defer file.close();
const text = try file.readToEndAlloc(allocator, 64 * 1024); 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 { 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 }); var file = try std.fs.openFileAbsolute(file_name, .{ .mode = .read_only });
defer file.close(); defer file.close();
const json = try file.readToEndAlloc(allocator, 64 * 1024); const json = try file.readToEndAlloc(allocator, 64 * 1024);
@ -502,7 +521,6 @@ fn read_cbor_config(
file_name: []const u8, file_name: []const u8,
cb: []const u8, cb: []const u8,
) !void { ) !void {
const cbor = @import("cbor");
var iter = cb; var iter = cb;
var field_name: []const u8 = undefined; var field_name: []const u8 = undefined;
while (cbor.matchString(&iter, &field_name) catch |e| switch (e) { 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 { 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 }); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true });
defer file.close(); defer file.close();

View file

@ -48,7 +48,7 @@ pub const conf = .{
.description = "Config", .description = "Config",
.color = 0x000000, .color = 0x000000,
.icon = "", .icon = "",
.extensions = .{ "conf", "config", ".gitconfig", "gui_config" }, .extensions = .{ "conf", "log", "config", ".gitconfig", "gui_config" },
.highlights = fish.highlights, .highlights = fish.highlights,
.comment = "#", .comment = "#",
.parser = fish.parser, .parser = fish.parser,

View file

@ -300,8 +300,15 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
const x = @min(self.plane.dim_x() -| 32, 8); 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)); 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; return more or self.fire != null;
} }