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
22 changes: 22 additions & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Zig fmt check

on:
pull_request:
branches: [ "main" ]

jobs:
zig-fmt:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1

- name: Zig fmt check
run: |
zig fmt --check .
3 changes: 1 addition & 2 deletions src/ascii_art.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");


// We stop assuming logo lines is of the same length as the info block
fn safeNextLine(iter: *std.mem.SplitIterator(u8, .sequence)) []const u8 {
return iter.next() orelse "";
Expand Down Expand Up @@ -42,7 +41,7 @@ pub fn printNeofetchStyle(
std.debug.print("{s}{s:<60}{s} {s}{s}Packages:{s} {}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, package_count });
std.debug.print("{s}{s:<60}{s} {s}{s}Hardware Model:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, hardware_model });
std.debug.print("{s}{s:<60}{s} {s}{s}CPU:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, cpu });
std.debug.print("{s}{s:<60}{s} {s}{s}GPU:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset,key_color, bold, reset, gpu });
std.debug.print("{s}{s:<60}{s} {s}{s}GPU:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, gpu });
std.debug.print("{s}{s:<60}{s} {s}{s}Terminal:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, terminal_name });
std.debug.print("{s}{s:<60}{s} {s}{s}Theme:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, theme });
std.debug.print("{s}{s:<60}{s} {s}{s}Icons:{s} {s}\n", .{ color, safeNextLine(&logo_lines), reset, key_color, bold, reset, icons });
Expand Down
24 changes: 4 additions & 20 deletions src/hardware.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ pub fn getGPUInfo(allocator: std.mem.Allocator) ![]u8 {
var lines = std.mem.splitSequence(u8, lspci_output, "\n");
while (lines.next()) |line| {
if (std.mem.indexOf(u8, line, "VGA compatible controller:")) |vga_index| {
const gpu_info = std.mem.trim(
u8,
line[vga_index + "VGA compatible controller:".len ..],
" "
);
const gpu_info = std.mem.trim(u8, line[vga_index + "VGA compatible controller:".len ..], " ");
return try allocator.dupe(u8, gpu_info);
}
}
Expand All @@ -71,11 +67,7 @@ pub fn getGPUInfo(allocator: std.mem.Allocator) ![]u8 {
var lines = std.mem.splitSequence(u8, glx_output, "\n");
while (lines.next()) |line| {
if (std.mem.startsWith(u8, line, "OpenGL renderer string:")) {
const gpu_info = std.mem.trim(
u8,
line["OpenGL renderer string:".len ..],
" "
);
const gpu_info = std.mem.trim(u8, line["OpenGL renderer string:".len..], " ");
return try allocator.dupe(u8, gpu_info);
}
}
Expand All @@ -88,11 +80,7 @@ pub fn getGPUInfo(allocator: std.mem.Allocator) ![]u8 {
var lines = std.mem.splitSequence(u8, vk_output, "\n");
while (lines.next()) |line| {
if (std.mem.indexOf(u8, line, "deviceName")) |idx| {
const gpu_info = std.mem.trim(
u8,
line[idx + "deviceName".len ..],
" :\t"
);
const gpu_info = std.mem.trim(u8, line[idx + "deviceName".len ..], " :\t");
return try allocator.dupe(u8, gpu_info);
}
}
Expand All @@ -109,11 +97,7 @@ pub fn getGPUInfo(allocator: std.mem.Allocator) ![]u8 {
const device = try device_file.readToEndAlloc(allocator, 16);
defer allocator.free(device);

const combined = try std.fmt.allocPrint(
allocator,
"PCI Vendor: {s}, Device: {s}",
.{ std.mem.trim(u8, vendor, "\n "), std.mem.trim(u8, device, "\n ") }
);
const combined = try std.fmt.allocPrint(allocator, "PCI Vendor: {s}, Device: {s}", .{ std.mem.trim(u8, vendor, "\n "), std.mem.trim(u8, device, "\n ") });
return combined;
} else |_| {}
} else |_| {}
Expand Down
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn main() !void {
const uptime = system.executeUptimeCommand(allocator, &[_][]const u8{ "uptime", "-p" }) catch |err| blk: {
// Because NixOS does not have a -p
if (err == error.CommandFailed) {
break :blk try system.executeUptimeCommand(allocator, &[_][]const u8{ "uptime" });
break :blk try system.executeUptimeCommand(allocator, &[_][]const u8{"uptime"});
} else {
return err;
}
Expand Down
3 changes: 1 addition & 2 deletions src/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn executeCommand(allocator: std.mem.Allocator, argv: []const []const u8) ![
return try result.toOwnedSlice(allocator);
}

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

Expand All @@ -143,4 +143,3 @@ pub fn executeUptimeCommand(allocator: std.mem.Allocator, argv: []const []const

return result.toOwnedSlice(allocator);
}