From daf8886999641e9d7b89291e626f0da4d05d1442 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Tue, 28 Dec 2021 20:30:42 +0200 Subject: Added more build-time config --- build.zig | 24 ++++++++++++++++-------- src/Buffer.zig | 8 ++++++-- src/Config.zig | 7 ++++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/build.zig b/build.zig index 140a64f..a3bd8c5 100644 --- a/build.zig +++ b/build.zig @@ -1,20 +1,28 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) void { +const Builder = std.build.Builder; +const SemanticVersion = std.SemanticVersion; + +const version = "0.3.0"; + +pub fn build(b: *Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); - const options_step = b.addOptions(); - options_step.addOption(std.SemanticVersion, "es_version", .{ - .major = 0, - .minor = 3, - .patch = 0, - }); + const options = b.addOptions(); + options.addOption( + SemanticVersion, + "es_version", + SemanticVersion.parse(version) catch unreachable, + ); + options.addOption(usize, "default_line_limit", 100); + options.addOption(usize, "default_page_overlap", 2); + options.addOption(usize, "default_tab_stop", 8); const exe = b.addExecutable("es", "src/main.zig"); exe.setTarget(target); exe.setBuildMode(mode); - exe.addOptions("es-config", options_step); + exe.addOptions("es-config", options); exe.install(); const run_cmd = exe.run(); diff --git a/src/Buffer.zig b/src/Buffer.zig index d7f051d..cb89935 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig @@ -1,4 +1,4 @@ -const es_config = @import("es-config"); +const conf = @import("es-config"); const std = @import("std"); const Allocator = std.mem.Allocator; @@ -193,7 +193,11 @@ pub fn drawRows(self: Buffer, writer: anytype, screenrows: usize, screencols: us } } } else if (self.rows.items.len == 0 and y == screenrows / 3) { - const welcome_data = try std.fmt.allocPrint(self.allocator, "ES -- version {}", .{es_config.es_version}); + const welcome_data = try std.fmt.allocPrint( + self.allocator, + "ES -- version {}", + .{conf.es_version}, + ); defer self.allocator.free(welcome_data); var welcome = welcome_data; if (welcome.len > screencols - 1) { diff --git a/src/Config.zig b/src/Config.zig index 1f11b65..900c2aa 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -1,5 +1,6 @@ // TODO: Change this to proper TOML in the future :) +const conf = @import("es-config"); const std = @import("std"); const Allocator = std.mem.Allocator; @@ -8,9 +9,9 @@ const Config = @This(); const config_path = "arkta/es/es.ini"; -line_limit: usize = 100, -page_overlap: usize = 2, -tab_stop: usize = 8, +line_limit: usize = conf.default_line_limit, +page_overlap: usize = conf.default_page_overlap, +tab_stop: usize = conf.default_tab_stop, pub fn readConfig(allocator: Allocator) !Config { var config = Config{}; -- cgit v1.2.3