Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install zig
uses: mlugg/setup-zig@v1
with:
version: 0.14.0
version: 0.15.1

- name: Build
run: zig build -Dtarget=x86_64-linux-gnu
Expand Down
16 changes: 10 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ pub fn build(b: *std.Build) void {
.name = "zfetch",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});

// This declares intent for the executable to be installed into the
Expand Down Expand Up @@ -55,9 +57,11 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});

const run_unit_tests = b.addRunArtifact(unit_tests);
Expand Down
45 changes: 23 additions & 22 deletions src/ascii_art.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const std = @import("std");

fn safeNextLine(iter: *std.mem.SplitIterator(u8, .sequence)) []const u8 {
return iter.next() orelse "";
}

pub fn printNeofetchStyle(
distro_name: []const u8,
desktop_env: []const u8,
Expand All @@ -19,33 +23,30 @@ pub fn printNeofetchStyle(
) !void {
const logo = getDistroLogo(distro_name);

// ANSI escape codes
const blue = "\x1b[38;2;135;206;250m"; // Blue text
const bold = "\x1b[1m"; // Bold text
const reset = "\x1b[0m"; // Reset formatting
const blue = "\x1b[38;2;135;206;250m";
const bold = "\x1b[1m";
const reset = "\x1b[0m";

// Split the logo into lines
var logo_lines = std.mem.splitSequence(u8, logo, "\n");

std.debug.print("{s}{s:<60}{s} {s}{s}{s}{s}\n", .{ color, logo_lines.next().?, reset, blue, bold, user_at_hostname, reset });
std.debug.print("{s}{s:<60}{s} {s}\n", .{ color, logo_lines.next().?, reset, "-----------------" });
std.debug.print("{s}{s:<60}{s} {s}{s}{s}{s}\n", .{ color, safeNextLine(&logo_lines), reset, blue, bold, user_at_hostname, reset });
std.debug.print("{s}{s:<60}{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, "-----------------" });

// Print each line with the label in bold
std.debug.print("{s}{s:<60}{s} {s}Distro: {s}\n", .{ color, logo_lines.next().?, reset, bold, distro_name });
std.debug.print("{s}{s:<60}{s} {s}DE/WM: {s}\n", .{ color, logo_lines.next().?, reset, bold, desktop_env });
std.debug.print("{s}{s:<60}{s} {s}Kernel Version: {s}", .{ color, logo_lines.next().?, reset, bold, kernel_version });
std.debug.print("{s}{s:<60}{s} {s}Uptime: {s}", .{ color, logo_lines.next().?, reset, bold, uptime });
std.debug.print("{s}{s:<60}{s} {s}Shell: {s}\n", .{ color, logo_lines.next().?, reset, bold, shell_version });
std.debug.print("{s}{s:<60}{s} {s}Packages: {}\n", .{ color, logo_lines.next().?, reset, bold, package_count });
std.debug.print("{s}{s:<60}{s} {s}Hardware Model: {s}\n", .{ color, logo_lines.next().?, reset, bold, hardware_model });
std.debug.print("{s}{s:<60}{s} {s}CPU: {s}\n", .{ color, logo_lines.next().?, reset, bold, cpu });
std.debug.print("{s}{s:<60}{s} {s}GPU: {s}\n", .{ color, logo_lines.next().?, reset, bold, gpu });
std.debug.print("{s}{s:<60}{s} {s}Terminal: {s}\n", .{ color, logo_lines.next().?, reset, bold, terminal_name });
std.debug.print("{s}{s:<60}{s} {s}Theme: {s}\n", .{ color, logo_lines.next().?, reset, bold, theme });
std.debug.print("{s}{s:<60}{s} {s}Icons: {s}\n", .{ color, logo_lines.next().?, reset, bold, icons });
std.debug.print("{s}{s:<60}{s} {s}Memory: {s}\n", .{ color, logo_lines.next().?, reset, bold, memory_info });
std.debug.print("{s}{s:<60}{s} {s}Distro: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, distro_name });
std.debug.print("{s}{s:<60}{s} {s}DE/WM: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, desktop_env });
std.debug.print("{s}{s:<60}{s} {s}Kernel Version: {s}", .{ color, safeNextLine(&logo_lines), reset, bold, kernel_version });
std.debug.print("{s}{s:<60}{s} {s}Uptime: {s}", .{ color, safeNextLine(&logo_lines), reset, bold, uptime });
std.debug.print("{s}{s:<60}{s} {s}Shell: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, shell_version });
std.debug.print("{s}{s:<60}{s} {s}Packages: {}\n", .{ color, safeNextLine(&logo_lines), reset, bold, package_count });
std.debug.print("{s}{s:<60}{s} {s}Hardware Model: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, hardware_model });
std.debug.print("{s}{s:<60}{s} {s}CPU: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, cpu });
std.debug.print("{s}{s:<60}{s} {s}GPU: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, gpu });
std.debug.print("{s}{s:<60}{s} {s}Terminal: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, terminal_name });
std.debug.print("{s}{s:<60}{s} {s}Theme: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, theme });
std.debug.print("{s}{s:<60}{s} {s}Icons: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, icons });
std.debug.print("{s}{s:<60}{s} {s}Memory: {s}\n", .{ color, safeNextLine(&logo_lines), reset, bold, memory_info });

// Print the remaining lines of the logo (if any)
// print remaining logo lines (if longer than info block)
while (logo_lines.next()) |logo_line| {
std.debug.print("{s}{s}{s}\n", .{ color, logo_line, reset });
}
Expand Down
10 changes: 5 additions & 5 deletions src/hardware.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ pub fn getGPUInfo(allocator: std.mem.Allocator) ![]u8 {
}

fn executeCommand(allocator: std.mem.Allocator, argv: []const []const u8) ![]const u8 {
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();
var result = std.ArrayListUnmanaged(u8){};
defer result.deinit(allocator);

var child = std.process.Child.init(argv, allocator);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;

try child.spawn();

const stdout = try child.stdout.?.reader().readAllAlloc(allocator, std.math.maxInt(usize));
const stdout = try child.stdout.?.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(stdout);

try result.appendSlice(stdout);
try result.appendSlice(allocator, stdout);

_ = try child.wait();

return result.toOwnedSlice();
return result.toOwnedSlice(allocator);
}
10 changes: 5 additions & 5 deletions src/machine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ pub fn getHardwareModel(allocator: std.mem.Allocator) ![]u8 {
}

fn executeCommand(allocator: std.mem.Allocator, argv: []const []const u8) ![]u8 {
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();
var result = std.ArrayListUnmanaged(u8){};
defer result.deinit(allocator);

var child = std.process.Child.init(argv, allocator);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;

try child.spawn();

const stdout = try child.stdout.?.reader().readAllAlloc(allocator, std.math.maxInt(usize));
const stdout = try child.stdout.?.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(stdout);

try result.appendSlice(stdout);
try result.appendSlice(allocator, stdout);

_ = try child.wait();

return result.toOwnedSlice();
return result.toOwnedSlice(allocator);
}
2 changes: 1 addition & 1 deletion src/package.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn getFedoraPackageCount(allocator: std.mem.Allocator) !usize {

try process.spawn();

const stdout = try process.stdout.?.reader().readAllAlloc(allocator, std.math.maxInt(usize));
const stdout = try process.stdout.?.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(stdout);

// Wait for the process to finish and check its exit code
Expand Down
11 changes: 6 additions & 5 deletions src/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,22 @@ fn parseMemInfoValue(line: []const u8) !u64 {
}

pub fn executeCommand(allocator: std.mem.Allocator, argv: []const []const u8) ![]u8 {
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();
var result = std.ArrayListUnmanaged(u8){}; // Andrew Kelley made me do this
defer result.deinit(allocator);

var child = std.process.Child.init(argv, allocator);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;

try child.spawn();

const stdout = try child.stdout.?.reader().readAllAlloc(allocator, std.math.maxInt(usize));
//const stdout = try child.stdout.?.reader(&buf).readAllAlloc(allocator, std.math.maxInt(usize));
const stdout = try child.stdout.?.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(stdout);

try result.appendSlice(stdout);
try result.appendSlice(allocator, stdout);

_ = try child.wait();

return result.toOwnedSlice();
return try result.toOwnedSlice(allocator);
}
2 changes: 1 addition & 1 deletion src/terminal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn parsePpidFromStat(stat_str: []const u8) !i32 {
}

fn isTerminalEmulator(process_name: []const u8) bool {
const terminal_emulators = [_][]const u8{ "alacritty", "kitty", "gnome-terminal", "xterm", "konsole", "urxvt", "st", "terminator", "tilix", "xfce4-terminal", "tmux", "screen", "terminology", "lxterminal", "rxvt", "sakura", "mate-terminal", "terminology", "konsole", "terminator" };
const terminal_emulators = [_][]const u8{ "alacritty", "kitty", "gnome-terminal", "xterm", "konsole", "urxvt", "st", "terminator", "tilix", "xfce4-terminal", "tmux", "screen", "terminology", "lxterminal", "rxvt", "sakura", "mate-terminal", "terminology", "konsole", "terminator", "ghostty" };
for (terminal_emulators) |emulator| {
if (std.mem.eql(u8, process_name, emulator)) {
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/theme.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ fn getGtkSettingsFromGsettings(allocator: std.mem.Allocator) !GtkSettings {
}
}
pub fn runCommand(allocator: std.mem.Allocator, argv: []const []const u8) ![]u8 {
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();
var result = std.ArrayListUnmanaged(u8){};
defer result.deinit(allocator);

var child = std.process.Child.init(argv, allocator);
child.stdout_behavior = .Pipe;
child.stderr_behavior = .Pipe;

try child.spawn();

const stdout = try child.stdout.?.reader().readAllAlloc(allocator, std.math.maxInt(usize));
const stdout = try child.stdout.?.readToEndAlloc(allocator, std.math.maxInt(usize));
defer allocator.free(stdout);

try result.appendSlice(stdout);
try result.appendSlice(allocator, stdout);

_ = try child.wait();

return result.toOwnedSlice();
return result.toOwnedSlice(allocator);
}
Loading