feat: add support for loading customized flow themes

This commit is contained in:
CJ van den Berg 2025-04-25 10:02:01 +02:00
parent 8f66e855ed
commit e8dbff76a1
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 64 additions and 14 deletions

View file

@ -94,14 +94,15 @@ pub fn main() !void {
}
if (highlight_line_end < highlight_line_start) {
try std.io.getStdErr().writer().print("invalid range\n", .{});
std.log.err("invalid range", .{});
std.process.exit(1);
}
const theme = get_theme_by_name(theme_name) orelse {
try std.io.getStdErr().writer().print("theme \"{s}\" not found\n", .{theme_name});
const theme, const parsed_theme = config_loader.get_theme_by_name(a, theme_name) orelse {
std.log.err("theme \"{s}\" not found", .{theme_name});
std.process.exit(1);
};
_ = parsed_theme;
const set_style: StyleFn = if (res.args.html != 0) set_html_style else set_ansi_style;
const unset_style: StyleFn = if (res.args.html != 0) unset_html_style else unset_ansi_style;
@ -174,7 +175,7 @@ fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8,
}
fn unknown_file_type(name: []const u8) noreturn {
std.io.getStdErr().writer().print("unknown file type \'{s}\'\n", .{name}) catch {};
std.log.err("unknown file type \'{s}\'\n", .{name});
std.process.exit(1);
}
@ -391,14 +392,6 @@ pub const fallbacks: []const FallBack = &[_]FallBack{
.{ .ts = "field", .tm = "variable" },
};
fn get_theme_by_name(name: []const u8) ?Theme {
for (themes.themes) |theme| {
if (std.mem.eql(u8, theme.name, name))
return theme;
}
return null;
}
fn list_themes(writer: Writer) !void {
var max_name_len: usize = 0;
for (themes.themes) |theme|