Skip to content

Commit

Permalink
Support color palettes in the config
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
Arnau478 committed May 15, 2024
1 parent 1ad4b4b commit 0433f62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/DisplayOptions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ show_ascii: bool,
skip_lines: bool,
/// Override the binary parser that is used
parser: ?hevi.Parser = null,
/// The color palette to use (ignored if `color` is `false`)
palette: hevi.ColorPalette = hevi.default_palette,

pub const OptionString = struct {
is_allocated: bool = false,
Expand Down
5 changes: 3 additions & 2 deletions src/hevi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub const PaletteColor = enum {
/// A color palette, that associates `PaletteColor`s to `TextColor`s
pub const ColorPalette = std.enums.EnumFieldStruct(PaletteColor, TextColor, null);

const palette: ColorPalette = .{
/// The default color palette
pub const default_palette: ColorPalette = .{
.normal = .{ .base = .yellow, .dim = false },
.normal_alt = .{ .base = .yellow, .dim = true },
.c1 = .{ .base = .red, .dim = false },
Expand Down Expand Up @@ -300,7 +301,7 @@ pub fn dump(allocator: std.mem.Allocator, data: []const u8, writer: std.io.AnyWr

for (colors, text_colors) |color, *text_color| {
text_color.* = switch (color) {
inline else => |c| @field(palette, @tagName(c)),
inline else => |c| @field(options.palette, @tagName(c)),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn getOptions(allocator: std.mem.Allocator, args: argparse.ParseResult, stdo
show_ascii: ?bool = null,
skip_lines: ?bool = null,
parser: ?hevi.Parser = null,
palette: ?hevi.ColorPalette = null,

comptime {
std.debug.assert(std.meta.fields(@This()).len == std.meta.fields(hevi.DisplayOptions).len);
Expand Down

0 comments on commit 0433f62

Please sign in to comment.