refactor: rename ascii.zig to dispaly.zig
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const ascii = @import("ascii.zig");
|
const display = @import("display.zig");
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
|
|
||||||
pub const Module = struct {
|
pub const Module = struct {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const ascii = @import("ascii.zig");
|
const display = @import("display.zig");
|
||||||
const detection = @import("detection.zig").os_module;
|
const detection = @import("detection.zig").os_module;
|
||||||
|
|
||||||
const Result = union(enum) {
|
const Result = union(enum) {
|
||||||
@@ -47,15 +47,15 @@ pub fn getFormattedUsernameHostname(allocator: std.mem.Allocator, color: []const
|
|||||||
return try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
|
return try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
|
||||||
color,
|
color,
|
||||||
username,
|
username,
|
||||||
ascii.Reset,
|
display.Reset,
|
||||||
color,
|
color,
|
||||||
hostname,
|
hostname,
|
||||||
ascii.Reset,
|
display.Reset,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedKernelInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedKernelInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedKernelInfo(allocator, "Kernel", ascii.Yellow);
|
return try getFormattedKernelInfo(allocator, "Kernel", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedKernelInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedKernelInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
@@ -63,73 +63,73 @@ pub fn getFormattedKernelInfo(allocator: std.mem.Allocator, key: []const u8, key
|
|||||||
defer allocator.free(kernel_info.kernel_name);
|
defer allocator.free(kernel_info.kernel_name);
|
||||||
defer allocator.free(kernel_info.kernel_release);
|
defer allocator.free(kernel_info.kernel_release);
|
||||||
|
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} {s}", .{ key_color, key, ascii.Reset, kernel_info.kernel_name, kernel_info.kernel_release }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} {s}", .{ key_color, key, display.Reset, kernel_info.kernel_name, kernel_info.kernel_release }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedOsInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedOsInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedOsInfo(allocator, "OS", ascii.Yellow);
|
return try getFormattedOsInfo(allocator, "OS", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedOsInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedOsInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const os_info = try detection.system.getOsInfo(allocator);
|
const os_info = try detection.system.getOsInfo(allocator);
|
||||||
defer allocator.free(os_info);
|
defer allocator.free(os_info);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, os_info }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, os_info }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedLocaleInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedLocaleInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedLocaleInfo(allocator, "Locale", ascii.Yellow);
|
return try getFormattedLocaleInfo(allocator, "Locale", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedLocaleInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedLocaleInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const locale = try detection.system.getLocale(allocator);
|
const locale = try detection.system.getLocale(allocator);
|
||||||
defer allocator.free(locale);
|
defer allocator.free(locale);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, locale }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, locale }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedUptimeInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedUptimeInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedUptimeInfo(allocator, "Uptime", ascii.Yellow);
|
return try getFormattedUptimeInfo(allocator, "Uptime", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedUptimeInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedUptimeInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const uptime = try detection.system.getSystemUptime();
|
const uptime = try detection.system.getSystemUptime();
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {} days, {} hours, {} minutes", .{ key_color, key, ascii.Reset, uptime.days, uptime.hours, uptime.minutes }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {} days, {} hours, {} minutes", .{ key_color, key, display.Reset, uptime.days, uptime.hours, uptime.minutes }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedPackagesInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedPackagesInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedPackagesInfo(allocator, "Packages", ascii.Yellow);
|
return try getFormattedPackagesInfo(allocator, "Packages", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedPackagesInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedPackagesInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const packages_info = try detection.packages.getPackagesInfo(allocator);
|
const packages_info = try detection.packages.getPackagesInfo(allocator);
|
||||||
defer allocator.free(packages_info);
|
defer allocator.free(packages_info);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s}{s}", .{ key_color, key, ascii.Reset, packages_info }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s}{s}", .{ key_color, key, display.Reset, packages_info }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedShellInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedShellInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedShellInfo(allocator, "Shell", ascii.Yellow);
|
return try getFormattedShellInfo(allocator, "Shell", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedShellInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedShellInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const shell = try detection.user.getShell(allocator);
|
const shell = try detection.user.getShell(allocator);
|
||||||
defer allocator.free(shell);
|
defer allocator.free(shell);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, shell[0..(shell.len - 1)] }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, shell[0..(shell.len - 1)] }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedCpuInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedCpuInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedCpuInfo(allocator, "Cpu", ascii.Yellow);
|
return try getFormattedCpuInfo(allocator, "Cpu", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedCpuInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedCpuInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const cpu_info = try detection.hardware.getCpuInfo(allocator);
|
const cpu_info = try detection.hardware.getCpuInfo(allocator);
|
||||||
defer allocator.free(cpu_info.cpu_name);
|
defer allocator.free(cpu_info.cpu_name);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, cpu_info.cpu_name, cpu_info.cpu_cores, cpu_info.cpu_max_freq }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, display.Reset, cpu_info.cpu_name, cpu_info.cpu_cores, cpu_info.cpu_max_freq }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedGpuInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedGpuInfo(allocator: std.mem.Allocator) !Result {
|
||||||
if (builtin.os.tag == .macos) {
|
if (builtin.os.tag == .macos) {
|
||||||
return try getFormattedGpuInfo(allocator, "Gpu", ascii.Yellow);
|
return try getFormattedGpuInfo(allocator, "Gpu", display.Yellow);
|
||||||
} else if (builtin.os.tag == .linux) {
|
} else if (builtin.os.tag == .linux) {
|
||||||
return try getFormattedGpuInfo(allocator, "Gpu", ascii.Yellow);
|
return try getFormattedGpuInfo(allocator, "Gpu", display.Yellow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ pub fn getFormattedGpuInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
|||||||
if (builtin.os.tag == .macos) {
|
if (builtin.os.tag == .macos) {
|
||||||
const gpu_info = try detection.hardware.getGpuInfo(allocator);
|
const gpu_info = try detection.hardware.getGpuInfo(allocator);
|
||||||
defer allocator.free(gpu_info.gpu_name);
|
defer allocator.free(gpu_info.gpu_name);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, gpu_info.gpu_name, gpu_info.gpu_cores, gpu_info.gpu_freq }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, display.Reset, gpu_info.gpu_name, gpu_info.gpu_cores, gpu_info.gpu_freq }) };
|
||||||
} else if (builtin.os.tag == .linux) {
|
} else if (builtin.os.tag == .linux) {
|
||||||
var formatted_gpu_info_list = std.array_list.Managed([]u8).init(allocator);
|
var formatted_gpu_info_list = std.array_list.Managed([]u8).init(allocator);
|
||||||
|
|
||||||
@@ -146,9 +146,9 @@ pub fn getFormattedGpuInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
|||||||
for (gpu_info_list.items) |g| {
|
for (gpu_info_list.items) |g| {
|
||||||
var formatted_gpu_info: []u8 = undefined;
|
var formatted_gpu_info: []u8 = undefined;
|
||||||
if ((g.gpu_cores == 0) or (g.gpu_freq == 0.0)) {
|
if ((g.gpu_cores == 0) or (g.gpu_freq == 0.0)) {
|
||||||
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, g.gpu_name });
|
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, g.gpu_name });
|
||||||
} else {
|
} else {
|
||||||
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, g.gpu_name, g.gpu_cores, g.gpu_freq });
|
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, display.Reset, g.gpu_name, g.gpu_cores, g.gpu_freq });
|
||||||
}
|
}
|
||||||
try formatted_gpu_info_list.append(formatted_gpu_info);
|
try formatted_gpu_info_list.append(formatted_gpu_info);
|
||||||
allocator.free(g.gpu_name);
|
allocator.free(g.gpu_name);
|
||||||
@@ -160,58 +160,58 @@ pub fn getFormattedGpuInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedRamInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedRamInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedRamInfo(allocator, "Ram", ascii.Yellow);
|
return try getFormattedRamInfo(allocator, "Ram", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedRamInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedRamInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const ram_info = if (builtin.os.tag == .macos) try detection.hardware.getRamInfo() else if (builtin.os.tag == .linux) try detection.hardware.getRamInfo(allocator);
|
const ram_info = if (builtin.os.tag == .macos) try detection.hardware.getRamInfo() else if (builtin.os.tag == .linux) try detection.hardware.getRamInfo(allocator);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {d:.2} / {d:.2} GiB ({}%)", .{ key_color, key, ascii.Reset, ram_info.ram_usage, ram_info.ram_size, ram_info.ram_usage_percentage }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {d:.2} / {d:.2} GiB ({}%)", .{ key_color, key, display.Reset, ram_info.ram_usage, ram_info.ram_size, ram_info.ram_usage_percentage }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedSwapInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedSwapInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedSwapInfo(allocator, "Swap", ascii.Yellow);
|
return try getFormattedSwapInfo(allocator, "Swap", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedSwapInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedSwapInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const swap_info = if (builtin.os.tag == .macos) try detection.hardware.getSwapInfo() else if (builtin.os.tag == .linux) try detection.hardware.getSwapInfo(allocator);
|
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| {
|
if (swap_info) |s| {
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {d:.2} / {d:.2} GiB ({}%)", .{ key_color, key, ascii.Reset, s.swap_usage, s.swap_size, s.swap_usage_percentage }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {d:.2} / {d:.2} GiB ({}%)", .{ key_color, key, display.Reset, s.swap_usage, s.swap_size, s.swap_usage_percentage }) };
|
||||||
} else {
|
} else {
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} Disabled", .{ key_color, key, ascii.Reset }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} Disabled", .{ key_color, key, display.Reset }) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedDiskInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedDiskInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedDiskInfo(allocator, "Disk", ascii.Yellow);
|
return try getFormattedDiskInfo(allocator, "Disk", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedDiskInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedDiskInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const disk_info = try detection.hardware.getDiskSize("/");
|
const disk_info = try detection.hardware.getDiskSize("/");
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s} ({s}):{s} {d:.2} / {d:.2} GB ({}%)", .{ key_color, key, disk_info.disk_path, ascii.Reset, disk_info.disk_usage, disk_info.disk_size, disk_info.disk_usage_percentage }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s} ({s}):{s} {d:.2} / {d:.2} GB ({}%)", .{ key_color, key, disk_info.disk_path, display.Reset, disk_info.disk_usage, disk_info.disk_size, disk_info.disk_usage_percentage }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedWindowManagerInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedWindowManagerInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedWindowManagerInfo(allocator, "WM", ascii.Yellow);
|
return try getFormattedWindowManagerInfo(allocator, "WM", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedWindowManagerInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedWindowManagerInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const wm = try detection.system.getWindowManagerInfo(allocator);
|
const wm = try detection.system.getWindowManagerInfo(allocator);
|
||||||
defer allocator.free(wm);
|
defer allocator.free(wm);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, wm }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, wm }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedTerminalNameInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedTerminalNameInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedTerminalNameInfo(allocator, "Terminal", ascii.Yellow);
|
return try getFormattedTerminalNameInfo(allocator, "Terminal", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedTerminalNameInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedTerminalNameInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
const terminal_name = try detection.user.getTerminalName(allocator);
|
const terminal_name = try detection.user.getTerminalName(allocator);
|
||||||
defer allocator.free(terminal_name);
|
defer allocator.free(terminal_name);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, terminal_name }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, display.Reset, terminal_name }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getDefaultFormattedNetInfo(allocator: std.mem.Allocator) !Result {
|
pub fn getDefaultFormattedNetInfo(allocator: std.mem.Allocator) !Result {
|
||||||
return try getFormattedNetInfo(allocator, "Local IP", ascii.Yellow);
|
return try getFormattedNetInfo(allocator, "Local IP", display.Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
@@ -219,7 +219,7 @@ pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
|||||||
|
|
||||||
var net_info_list = try detection.network.getNetInfo(allocator);
|
var net_info_list = try detection.network.getNetInfo(allocator);
|
||||||
for (net_info_list.items) |n| {
|
for (net_info_list.items) |n| {
|
||||||
try formatted_net_info_list.append(try std.fmt.allocPrint(allocator, "{s}{s} ({s}):{s} {s}", .{ key_color, key, n.interface_name, ascii.Reset, n.ipv4_addr }));
|
try formatted_net_info_list.append(try std.fmt.allocPrint(allocator, "{s}{s} ({s}):{s} {s}", .{ key_color, key, n.interface_name, display.Reset, n.ipv4_addr }));
|
||||||
allocator.free(n.interface_name);
|
allocator.free(n.interface_name);
|
||||||
allocator.free(n.ipv4_addr);
|
allocator.free(n.ipv4_addr);
|
||||||
}
|
}
|
||||||
@@ -229,5 +229,5 @@ pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedCustom(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedCustom(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ key_color, key, ascii.Reset }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ key_color, key, display.Reset }) };
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main.zig
10
src/main.zig
@@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const detection = @import("detection.zig").os_module;
|
const detection = @import("detection.zig").os_module;
|
||||||
const ascii = @import("ascii.zig");
|
const display = @import("display.zig");
|
||||||
const config = @import("config.zig");
|
const config = @import("config.zig");
|
||||||
const formatters = @import("formatters.zig");
|
const formatters = @import("formatters.zig");
|
||||||
|
|
||||||
@@ -32,10 +32,10 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: {
|
const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: {
|
||||||
var buf: [32]u8 = undefined;
|
var buf: [32]u8 = undefined;
|
||||||
const rgb = try ascii.hexColorToRgb(color);
|
const rgb = try display.hexColorToRgb(color);
|
||||||
const formatted_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
|
const formatted_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
|
||||||
break :blk formatted_color;
|
break :blk formatted_color;
|
||||||
} else ascii.Yellow;
|
} else display.Yellow;
|
||||||
|
|
||||||
try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname));
|
try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname));
|
||||||
allocator.free(hostname);
|
allocator.free(hostname);
|
||||||
@@ -59,7 +59,7 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
} else if (conf) |c| {
|
} else if (conf) |c| {
|
||||||
for (modules_types.items, c.value.modules) |module_type, module| {
|
for (modules_types.items, c.value.modules) |module_type, module| {
|
||||||
var buf: [32]u8 = undefined;
|
var buf: [32]u8 = undefined;
|
||||||
const rgb = try ascii.hexColorToRgb(module.key_color);
|
const rgb = try display.hexColorToRgb(module.key_color);
|
||||||
const key_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
|
const key_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
|
||||||
|
|
||||||
const result = try formatters.formatters[@intFromEnum(module_type)](allocator, module.key, key_color);
|
const result = try formatters.formatters[@intFromEnum(module_type)](allocator, module.key, key_color);
|
||||||
@@ -75,5 +75,5 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
|
|
||||||
// TODO: rename ascii.zig in display.zig
|
// TODO: rename ascii.zig in display.zig
|
||||||
// TODO: return the formatted ascii and modules to print instead of directly print them
|
// TODO: return the formatted ascii and modules to print instead of directly print them
|
||||||
try ascii.printAsciiAndModules(allocator, io, config.getAsciiPath(conf), modules_list);
|
try display.printAsciiAndModules(allocator, io, config.getAsciiPath(conf), modules_list);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user