feat: add custom ascii art
This commit is contained in:
@@ -65,18 +65,23 @@ test "parse ffffff" {
|
|||||||
try std.testing.expect((result.r == 255) and (result.g == 255) and (result.b == 255));
|
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_buffer: [2048]u8 = undefined;
|
||||||
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
|
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
|
||||||
const stdout = &stdout_writer.interface;
|
const stdout = &stdout_writer.interface;
|
||||||
|
|
||||||
// const ascii_art_path = "./assets/ascii/guy_fawks.txt";
|
var ascii_art_data: []const u8 = undefined;
|
||||||
// var file = try std.fs.cwd().openFile(ascii_art_path, .{});
|
if (ascii_art_path) |ascii| {
|
||||||
// defer file.close();
|
var ascii_file = try std.fs.cwd().openFile(ascii, .{});
|
||||||
// const ascii_art_data = try file.readToEndAlloc(allocator, std.math.maxInt(usize));
|
defer ascii_file.close();
|
||||||
// defer allocator.free(ascii_art_data);
|
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');
|
var lines = std.mem.splitScalar(u8, ascii_art_data, '\n');
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ pub const Module = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Config = struct {
|
pub const Config = struct {
|
||||||
|
ascii_abs_path: ?[]u8 = null,
|
||||||
modules: []Module,
|
modules: []Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ pub const ModuleType = enum {
|
|||||||
custom,
|
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) {
|
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);
|
var modules_list = std.array_list.Managed(ModuleType).init(allocator);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user