feat: add custom ascii art

This commit is contained in:
utox39
2025-09-10 14:21:22 +02:00
parent 3cfae25a75
commit 20e2ef80d2
3 changed files with 18 additions and 8 deletions

View File

@@ -65,18 +65,23 @@ test "parse ffffff" {
try std.testing.expect((result.r == 255) and (result.g == 255) and (result.b == 255));
}
pub fn printAscii(allocator: std.mem.Allocator, sys_info_list: std.array_list.Managed([]u8)) !void {
pub fn printAscii(allocator: std.mem.Allocator, ascii_art_path: ?[]u8, sys_info_list: std.array_list.Managed([]u8)) !void {
var stdout_buffer: [2048]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
const stdout = &stdout_writer.interface;
// const ascii_art_path = "./assets/ascii/guy_fawks.txt";
// var file = try std.fs.cwd().openFile(ascii_art_path, .{});
// defer file.close();
// const ascii_art_data = try file.readToEndAlloc(allocator, std.math.maxInt(usize));
// defer allocator.free(ascii_art_data);
var ascii_art_data: []const u8 = undefined;
if (ascii_art_path) |ascii| {
var ascii_file = try std.fs.cwd().openFile(ascii, .{});
defer ascii_file.close();
ascii_art_data = try ascii_file.readToEndAlloc(allocator, std.math.maxInt(usize));
} else {
ascii_art_data = @embedFile("./assets/ascii/guy_fawks.txt");
}
const ascii_art_data = @embedFile("./assets/ascii/guy_fawks.txt");
defer if (ascii_art_path != null) {
allocator.free(ascii_art_data);
};
var lines = std.mem.splitScalar(u8, ascii_art_data, '\n');

View File

@@ -9,6 +9,7 @@ pub const Module = struct {
};
pub const Config = struct {
ascii_abs_path: ?[]u8 = null,
modules: []Module,
};
@@ -29,6 +30,10 @@ pub const ModuleType = enum {
custom,
};
pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 {
return config.?.value.ascii_abs_path;
}
pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.array_list.Managed(ModuleType) {
var modules_list = std.array_list.Managed(ModuleType).init(allocator);

View File

@@ -70,5 +70,5 @@ pub fn main() !void {
}
}
try ascii.printAscii(allocator, sys_info_list);
try ascii.printAscii(allocator, config.getAsciiPath(conf), sys_info_list);
}