diff --git a/src/cli.zig b/src/cli.zig index 3174936..f54ce5d 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -4,6 +4,7 @@ const std = @import("std"); const cova = @import("cova"); const assets = @import("assets.zig"); +const Speed = main.Speed; const Color = main.Color; const Style = main.Style; const Mode = main.Mode; @@ -69,6 +70,7 @@ pub const CommandT = cova.Command.Custom(.{ }, .val_config = .{ .custom_types = &.{ + Speed, Color, Style, Mode, @@ -133,6 +135,16 @@ pub const setup_cmd: CommandT = .{ .default_val = 0, }), }, + .{ + .name = "speed", + .description = "Set speed (fast, slow).", + .long_name = "speed", + .val = ValueT.ofType(Speed, .{ + .name = "speed_val", + .default_val = Speed.fast, + .alias_child_type = "string", + }), + }, .{ .name = "version", .description = "Show the 'xtxf' version.", diff --git a/src/main.zig b/src/main.zig index a4cd168..12dccdb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,7 +23,8 @@ const VERSION = if (build_opt.gxt.dirty == null) HEAD_HASH ++ "-unverified" else const FRAME = 39730492; -pub const Mode = enum(u8) { binary, decimal, hexadecimal, textual }; +pub const Speed = enum { slow, fast }; +pub const Mode = enum { binary, decimal, hexadecimal, textual }; pub const Style = enum { default, columns, crypto, grid, blocks }; pub const Color = enum(u32) { default = tb.TB_DEFAULT, red = tb.TB_RED, green = tb.TB_GREEN, blue = tb.TB_BLUE, yellow = tb.TB_YELLOW, magenta = tb.TB_MAGENTA }; @@ -135,6 +136,7 @@ const Core = struct { const Handler = struct { mutex: Mutex = Mutex{}, halt: bool = true, + speed: Speed = .fast, duration: u32 = 0, pause: bool = false, mode: Mode = Mode.binary, @@ -250,7 +252,10 @@ fn printCells(core: *Core, handler: *Handler, rand: std.rand.Random) !void { _ = tb.tb_present(); core.setRendering(false); - std.time.sleep(FRAME); + std.time.sleep(switch (handler.speed) { + .slow => FRAME * 2, + .fast => FRAME, + }); } } @@ -327,6 +332,10 @@ pub fn main() !void { handler.duration = try time.val.getAs(u32); } + if (opts.get("speed")) |speed| { + handler.speed = try speed.val.getAs(Speed); + } + if (opts.get("pulse")) |pulse| { core.pulse = try pulse.val.getAs(bool); } diff --git a/test/cli.zig b/test/cli.zig index 1ec6db0..5885f3b 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -22,6 +22,13 @@ test "default" { try std.testing.expectEqual(term, std.process.Child.Term{ .Exited = 0 }); } +test "speed" { + const argv = [_][]const u8{ exe_path, "--time=1", "-s=default", "--speed=slow" }; + const term = try runner(argv); + + try std.testing.expectEqual(term, std.process.Child.Term{ .Exited = 0 }); +} + test "mode: decimal" { const argv = [_][]const u8{ exe_path, "--time=1", "-m=decimal" }; const term = try runner(argv);