feat: add ascii art
This commit is contained in:
54
src/ascii.zig
Normal file
54
src/ascii.zig
Normal file
@@ -0,0 +1,54 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn selectAscii() void {}
|
||||
|
||||
pub fn printAscii(allocator: std.mem.Allocator, sys_info_list: std.ArrayList([]u8)) !void {
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
// 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);
|
||||
|
||||
const ascii_art_data = @embedFile("./assets/ascii/guy_fawks.txt");
|
||||
|
||||
var lines = std.mem.splitScalar(u8, ascii_art_data, '\n');
|
||||
|
||||
var ascii_art_content_list = std.ArrayList([]const u8).init(allocator);
|
||||
defer ascii_art_content_list.deinit();
|
||||
|
||||
while (lines.next()) |line| {
|
||||
try ascii_art_content_list.append(line);
|
||||
}
|
||||
|
||||
const ascii_art_items = ascii_art_content_list.items;
|
||||
const sys_info_items = sys_info_list.items;
|
||||
|
||||
const ascii_art_len: usize = ascii_art_items.len;
|
||||
const sys_info_len: usize = sys_info_items.len;
|
||||
const max_len: usize = if (ascii_art_len > sys_info_len) ascii_art_len else sys_info_len;
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < max_len) : (i += 1) {
|
||||
if (i < ascii_art_len) {
|
||||
try stdout.print("{s:<40} \t", .{ascii_art_items[i]});
|
||||
} else {
|
||||
try stdout.print("{s:<40}", .{""});
|
||||
}
|
||||
try bw.flush();
|
||||
|
||||
if (i < sys_info_len) {
|
||||
try stdout.print("{s}\n", .{sys_info_items[i]});
|
||||
} else {
|
||||
try stdout.print("\n", .{});
|
||||
}
|
||||
try bw.flush();
|
||||
}
|
||||
|
||||
for (sys_info_list.items) |item| {
|
||||
allocator.free(item);
|
||||
}
|
||||
}
|
||||
28
src/assets/ascii/guy_fawks.txt
Normal file
28
src/assets/ascii/guy_fawks.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
████████████████
|
||||
██████░░░░░░░░░░░░░░░░██████
|
||||
██░░░░░░ ░░░░░░██
|
||||
██░░ ░░██
|
||||
██░░ ░░██
|
||||
██ ██████ ██████ ██
|
||||
██ ░░░░░░░░████ ████░░░░░░░░ ██
|
||||
██ ░░████ ████░░ ██
|
||||
██ ░░░░ ░░░░ ██
|
||||
██░░ ░░██████░░░░ ░░░░██████░░ ░░██
|
||||
██░░░░██████████░░ ░░██████████░░░░██
|
||||
██░░ ░░░░░░░░ ░░ ░░ ░░░░░░░░ ░░██
|
||||
██ ░░ ░░ ██
|
||||
██ ░░░░░░ ░░ ░░ ░░░░░░ ██
|
||||
██ ░░░░░░ ░░ ░░ ░░░░░░ ██
|
||||
██░░ ░░ ░░ ░░██
|
||||
██░░░░██ ██░░░░██ ██░░░░██
|
||||
██░░ ██████░░████████████░░██████ ░░██
|
||||
██ ░░ ██████████ ██████████ ░░ ██
|
||||
██ ░░░░ ░░░░░░░░░░░░ ░░░░ ██
|
||||
██ ░░ ░░ ██
|
||||
██ ░░ ░░░░░░████░░░░░░ ░░ ██
|
||||
██░░ ░░ ████ ░░ ░░██
|
||||
██░░ ░░████░░ ░░██
|
||||
██░░ ░░████░░ ░░██
|
||||
██░░░░ ████ ░░░░██
|
||||
████░░████░░████
|
||||
████████
|
||||
83
src/main.zig
83
src/main.zig
@@ -1,74 +1,66 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const detection = @import("detection.zig").os_module;
|
||||
const ascii = @import("ascii.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
const stdout_file = std.io.getStdOut().writer();
|
||||
var bw = std.io.bufferedWriter(stdout_file);
|
||||
const stdout = bw.writer();
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
defer _ = gpa.deinit();
|
||||
|
||||
var sys_info_list = std.ArrayList([]u8).init(allocator);
|
||||
defer sys_info_list.deinit();
|
||||
|
||||
var buf: [1024]u8 = undefined;
|
||||
|
||||
const username = try detection.user.getUsername(allocator);
|
||||
const hostname = try detection.system.getHostname(allocator);
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "{s}@{s}", .{ username, hostname })));
|
||||
allocator.free(hostname);
|
||||
allocator.free(username);
|
||||
|
||||
const separtor_buffer = try allocator.alloc(u8, username.len + hostname.len + 1);
|
||||
@memset(separtor_buffer, '-');
|
||||
try sys_info_list.append(separtor_buffer);
|
||||
|
||||
const kernel_info = try detection.system.getKernelInfo(allocator);
|
||||
try stdout.print("Kernel: {s} {s}\n", .{ kernel_info.kernel_name, kernel_info.kernel_release });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try kernel_info.toStr(&buf)));
|
||||
allocator.free(kernel_info.kernel_name);
|
||||
allocator.free(kernel_info.kernel_release);
|
||||
|
||||
const os_info = try detection.system.getOsInfo(allocator);
|
||||
try stdout.print("OS: {s}\n", .{os_info});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "OS: {s}", .{os_info})));
|
||||
allocator.free(os_info);
|
||||
|
||||
const username = try detection.user.getUsername(allocator);
|
||||
try stdout.print("User: {s}\n", .{username});
|
||||
try bw.flush();
|
||||
allocator.free(username);
|
||||
|
||||
const hostname = try detection.system.getHostname(allocator);
|
||||
try stdout.print("Hostname: {s}\n", .{hostname});
|
||||
try bw.flush();
|
||||
allocator.free(hostname);
|
||||
|
||||
const locale = try detection.system.getLocale(allocator);
|
||||
try stdout.print("Locale: {s}\n", .{locale});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Locale: {s}", .{locale})));
|
||||
allocator.free(locale);
|
||||
|
||||
const uptime = try detection.system.getSystemUptime();
|
||||
try stdout.print("Uptime: {} days, {} hours, {} minutes\n", .{ uptime.days, uptime.hours, uptime.minutes });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try uptime.toStr(&buf)));
|
||||
|
||||
if (builtin.os.tag == .macos) {
|
||||
const packages_info = try detection.packages.getPackagesInfo(allocator);
|
||||
try stdout.print("Packages:{s}\n", .{packages_info});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Packages:{s}", .{packages_info})));
|
||||
allocator.free(packages_info);
|
||||
} else if (builtin.os.tag == .linux) {
|
||||
try stdout.print("Packages: WIP\n", .{});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Packages: WIP", .{})));
|
||||
}
|
||||
|
||||
const shell = try detection.user.getShell(allocator);
|
||||
try stdout.print("Shell: {s}", .{shell});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Shell: {s}", .{shell[0..(shell.len - 1)]})));
|
||||
allocator.free(shell);
|
||||
|
||||
const cpu_info = try detection.hardware.getCpuInfo(allocator);
|
||||
try stdout.print("Cpu: {s} ({}) @ {d:.2} GHz\n", .{ cpu_info.cpu_name, cpu_info.cpu_cores, cpu_info.cpu_max_freq });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try cpu_info.toStr(&buf)));
|
||||
allocator.free(cpu_info.cpu_name);
|
||||
|
||||
if (builtin.os.tag == .macos) {
|
||||
const gpu_info = try detection.hardware.getGpuInfo(allocator);
|
||||
try stdout.print("Gpu: {s} ({}) @ {d:.2} GHz\n", .{ gpu_info.gpu_name, gpu_info.gpu_cores, gpu_info.gpu_freq });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try gpu_info.toStr(&buf)));
|
||||
allocator.free(gpu_info.gpu_name);
|
||||
} else if (builtin.os.tag == .linux) {
|
||||
try stdout.print("Gpu: WIP\n", .{});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Gpu: WIP", .{})));
|
||||
}
|
||||
|
||||
var ram_info = detection.hardware.RamInfo{
|
||||
@@ -81,32 +73,31 @@ pub fn main() !void {
|
||||
} else if (builtin.os.tag == .linux) {
|
||||
ram_info = try detection.hardware.getRamInfo(allocator);
|
||||
}
|
||||
try stdout.print("Ram: {d:.2} / {d:.2} GiB ({}%)\n", .{ ram_info.ram_usage, ram_info.ram_size, ram_info.ram_usage_percentage });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try ram_info.toStr(&buf)));
|
||||
|
||||
const swap_info = if (builtin.os.tag == .macos) try detection.hardware.getSwapInfo() else if (builtin.os.tag == .linux) try detection.hardware.getSwapInfo(allocator);
|
||||
if (swap_info) |s| {
|
||||
try stdout.print("Swap: {d:.2} / {d:.2} GiB ({}%)\n", .{ s.swap_usage, s.swap_size, s.swap_usage_percentage });
|
||||
try sys_info_list.append(try allocator.dupe(u8, try s.toStr(&buf)));
|
||||
} else {
|
||||
try stdout.print("Swap: Disabled\n", .{});
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Swap: Disabled", .{})));
|
||||
}
|
||||
try bw.flush();
|
||||
|
||||
const diskInfo = try detection.hardware.getDiskSize("/");
|
||||
try stdout.print("Disk ({s}): {d:.2} / {d:.2} GB ({}%)\n", .{ diskInfo.disk_path, diskInfo.disk_usage, diskInfo.disk_size, diskInfo.disk_usage_percentage });
|
||||
try bw.flush();
|
||||
const disk_info = try detection.hardware.getDiskSize("/");
|
||||
try sys_info_list.append(try allocator.dupe(u8, try disk_info.toStr(&buf)));
|
||||
|
||||
const terminal_name = try detection.user.getTerminalName(allocator);
|
||||
try stdout.print("Terminal: {s}\n", .{terminal_name});
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try std.fmt.bufPrint(&buf, "Terminal: {s}", .{terminal_name})));
|
||||
allocator.free(terminal_name);
|
||||
|
||||
const net_info_list = try detection.network.getNetInfo(allocator);
|
||||
for (net_info_list.items) |n| {
|
||||
try stdout.print("Local IP ({s}): {s}\n", .{ n.interface_name, n.ipv4_addr });
|
||||
try bw.flush();
|
||||
try sys_info_list.append(try allocator.dupe(u8, try n.toStr(&buf)));
|
||||
allocator.free(n.interface_name);
|
||||
allocator.free(n.ipv4_addr);
|
||||
}
|
||||
net_info_list.deinit();
|
||||
|
||||
@memset(&buf, 0);
|
||||
|
||||
try ascii.printAscii(allocator, sys_info_list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user