diff --git a/README.md b/README.md index c8b6aa8..7621fb7 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,5 @@ zig build ## Usage ```sh -xtxf -a -m hexadecimal -s crypto +xtxf -m hexadecimal -s crypto -a bold ``` diff --git a/src/cli.zig b/src/cli.zig index f6883ee..5453c7a 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -8,6 +8,7 @@ const Speed = main.Speed; const Color = main.Color; const Style = main.Style; const Mode = main.Mode; +const Accent = main.Accent; pub const CommandT = cova.Command.Custom(.{ .global_help_prefix = assets.help_prefix, @@ -74,6 +75,7 @@ pub const CommandT = cova.Command.Custom(.{ Color, Style, Mode, + Accent, }, }, }); @@ -84,7 +86,7 @@ pub const setup_cmd: CommandT = .{ .name = "xtxf", .description = "2D matrix screensaver.", .examples = &.{ - "xtxf -a -m decimal -c red -s crypto", + "xtxf -m decimal -s crypto -a bold,dim", }, .sub_cmds_mandatory = false, .sub_cmds = &.{ @@ -129,22 +131,14 @@ pub const setup_cmd: CommandT = .{ }, .{ .name = "accents", - .description = "Enable symbol accentuations.", + .description = "Enable symbol accentuations (bold, bright, dim, pulse).", .short_name = 'a', .long_name = "accents", - .val = ValueT.ofType(bool, .{ - .name = "accents_flag", - .default_val = false, - }), - }, - .{ - .name = "pulse", - .description = "Enable pulse blocks.", - .short_name = 'p', - .long_name = "pulse", - .val = ValueT.ofType(bool, .{ - .name = "pulse_flag", - .default_val = false, + .val = ValueT.ofType(Accent, .{ + .name = "accents", + .alias_child_type = "string", + .set_behavior = .Multi, + .max_entries = 4, }), }, .{ diff --git a/src/main.zig b/src/main.zig index af24c94..af2bae1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -55,6 +55,13 @@ pub const Style = enum { rain, }; +pub const Accent = enum { + bold, + bright, + dim, + pulse, +}; + pub const Color = enum(u32) { default = tb.TB_DEFAULT, red = tb.TB_RED, @@ -145,11 +152,10 @@ const Core = struct { color: Color = .default, style: Style = .default, speed: Speed = .normal, + accents: ?[]const Accent = null, debug: bool = false, active: bool = false, rendering: bool = false, - accents: bool = false, - pulse: bool = false, bg: u32 = tb.TB_DEFAULT, width: u32 = 0, height: u32 = 0, @@ -292,25 +298,26 @@ const Core = struct { var color = @intFromEnum(self.color); var bg = self.bg; - if (self.pulse) { - const blank = @mod(rand.int(u8), 255); - - // small probability - if (blank >= 254) { - bg = bg | tb.TB_REVERSE; - } - } - - if (self.accents) { - const bold = rand.boolean(); - const dim = rand.boolean(); - - if (bold) { - color = color | tb.TB_BOLD; - } - - if (dim) { - color = color | tb.TB_DIM; + if (self.accents) |accents| { + for (accents) |accent| { + switch (accent) { + .bold => { + if (rand.boolean()) color = color | tb.TB_BOLD; + }, + .bright => { + if (rand.boolean()) color = color | tb.TB_BRIGHT; + }, + .dim => { + if (rand.boolean()) color = color | tb.TB_DIM; + }, + .pulse => { + const blank = @mod(rand.int(u8), 255); + // small probability + if (blank >= 254) { + bg = bg | tb.TB_REVERSE; + } + }, + } } } @@ -652,11 +659,7 @@ pub fn main() !void { } if (opts.get("accents")) |accents| { - core.accents = try accents.val.getAs(bool); - } - - if (opts.get("pulse")) |pulse| { - core.pulse = try pulse.val.getAs(bool); + core.accents = accents.val.getAllAs(Accent) catch null; } if (main_cmd.checkFlag("version")) { diff --git a/test/cli.zig b/test/cli.zig index 1f45c14..2112016 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -47,7 +47,7 @@ test "default" { } test "accents" { - const argv = [4][]const u8{ exe_path, if (live) "--time=1" else "--debug", "-s=default", "--accents" }; + const argv = [4][]const u8{ exe_path, if (live) "--time=1" else "--debug", "-s=default", "--accents=bold,dim,bright,pulse" }; const proc = try runner(argv); defer { std.testing.allocator.free(proc.out); diff --git a/test/streams.zig b/test/streams.zig index 5a64982..cc330fa 100644 --- a/test/streams.zig +++ b/test/streams.zig @@ -15,29 +15,29 @@ pub const default = ; pub const accents = - \\info(xtxf): 0: 9x7 32768/0 - \\info(xtxf): 0: 9x8 32768/0 - \\info(xtxf): 0: 9x9 0/0 - \\info(xtxf): 0: 10x0 256/0 - \\info(xtxf): 0: 10x1 256/0 - \\info(xtxf): 0: 10x2 32768/0 - \\info(xtxf): 1: 10x3 33024/0 - \\info(xtxf): 1: 10x4 32768/0 - \\info(xtxf): 0: 10x5 256/0 - \\info(xtxf): 1: 10x6 32768/0 - \\info(xtxf): 1: 10x7 32768/0 - \\info(xtxf): 0: 10x8 33024/0 - \\info(xtxf): 0: 10x9 32768/0 - \\info(xtxf): 0: 11x0 0/0 - \\info(xtxf): 0: 11x1 33024/0 - \\info(xtxf): 0: 11x2 32768/0 - \\info(xtxf): 1: 11x3 33024/0 - \\info(xtxf): 1: 11x4 33024/0 + \\info(xtxf): 1: 9x7 49408/0 + \\info(xtxf): 0: 9x8 49152/0 + \\info(xtxf): 1: 9x9 0/0 + \\info(xtxf): 1: 10x0 256/0 + \\info(xtxf): 0: 10x1 32768/0 + \\info(xtxf): 1: 10x2 16640/0 + \\info(xtxf): 0: 10x3 0/0 + \\info(xtxf): 0: 10x4 33024/0 + \\info(xtxf): 1: 10x5 32768/0 + \\info(xtxf): 1: 10x6 256/0 + \\info(xtxf): 1: 10x7 0/0 + \\info(xtxf): 0: 10x8 49408/0 + \\info(xtxf): 0: 10x9 16640/0 + \\info(xtxf): 1: 11x0 0/0 + \\info(xtxf): 1: 11x1 16384/0 + \\info(xtxf): 1: 11x2 33024/0 + \\info(xtxf): 1: 11x3 49408/0 + \\info(xtxf): 1: 11x4 16640/0 \\info(xtxf): 1: 11x5 33024/0 - \\info(xtxf): 1: 11x6 32768/0 + \\info(xtxf): 1: 11x6 0/0 \\info(xtxf): 0: 11x7 32768/0 - \\info(xtxf): 1: 11x8 256/0 - \\info(xtxf): 1: 11x9 32768/0 + \\info(xtxf): 0: 11x8 16640/0 + \\info(xtxf): 1: 11x9 16640/0 \\info(xtxf): Exiting... \\ ;