34 Commits

Author SHA1 Message Date
utox39
0aec3d8e5b Merge pull request #20 from utox39/fix/invalid-module-memory-leak
Fix a memory leak when the InvalidModule error occurs
2025-10-04 18:06:07 +02:00
utox39
dd2f50c79c build: bump version to 0.22.1 2025-10-04 17:57:29 +02:00
utox39
16bb74c47b fix(config): fix a memory leak when the InvalidModule error occurs 2025-10-04 17:55:50 +02:00
utox39
20f9c6e1d5 Merge pull request #19 from utox39/build/remove-archive-creation
build: remove archive creation
2025-10-03 15:02:11 +02:00
utox39
b09443db4d build: remove archive-creation 2025-10-03 15:00:30 +02:00
utox39
dd3b79b32d Merge pull request #18 from utox39/build/fix-artifact-output
build: use the correct artifact path
2025-10-03 14:45:42 +02:00
utox39
22376139f2 build: use the correct artifact path 2025-10-03 14:43:25 +02:00
utox39
a835074ee6 docs(README): update README 2025-09-14 19:38:25 +02:00
utox39
3d16102f37 docs(README): update README 2025-09-14 19:23:02 +02:00
utox39
24a5e98089 docs(README): update README 2025-09-13 21:18:44 +02:00
utox39
f03f7e163c chore: add screenshots 2025-09-13 21:17:52 +02:00
utox39
69d02a4bb7 Merge pull request #16 from utox39/feat/add-username-hostname-color
Feat/add username hostname color
2025-09-13 20:07:32 +02:00
utox39
6a86a81fcc build: bump version to 0.22.0 2025-09-13 20:04:27 +02:00
utox39
a125053c70 refactor(config): remove unused import 2025-09-13 19:52:14 +02:00
utox39
d9ec3a7de7 feat: add logic for username and hostname colors 2025-09-13 18:41:15 +02:00
utox39
5f6460f46e feat(formatters): add getFormattedUsernameHostname function 2025-09-13 18:36:32 +02:00
utox39
aab5212e6e feat(config): add username_hostname_color field and getUsernameHostname function 2025-09-13 18:33:04 +02:00
utox39
abff59b7d6 fix(config): fix null value access when config file are not used 2025-09-13 17:40:53 +02:00
utox39
1dc0559b8e Merge pull request #15 from utox39/feat/handle-ioctl-error
Feat/handle ioctl error
2025-09-12 02:42:30 +02:00
utox39
2b32119bc7 fix: minor fix 2025-09-12 02:41:20 +02:00
utox39
837b7cd5c4 build: bump version to 0.21.1 2025-09-12 02:34:02 +02:00
utox39
6317269c4f test(utils): handle IoctlFailed error using default values 2025-09-12 02:31:31 +02:00
utox39
989b5b2305 feat(ascii): handle the IoctlFailed error using default values 2025-09-12 02:30:18 +02:00
utox39
c32318dac2 Merge pull request #14 from utox39/build/cross-compilation
Build/cross compilation
2025-09-12 02:14:07 +02:00
utox39
c64f2f384d docs(README): update README 2025-09-12 02:11:29 +02:00
utox39
c82622cf8e build: fix indentation 2025-09-12 02:00:56 +02:00
utox39
9babb021f1 chore: add github workflows 2025-09-12 01:54:32 +02:00
utox39
ef8b6bcebd Merge pull request #13 from utox39/feat/custom-ascii
Feat/custom ascii
2025-09-10 14:52:20 +02:00
utox39
acc4563d2d docs(README): update README 2025-09-10 14:47:12 +02:00
utox39
ea966cd474 build: bump version to 0.21.0 2025-09-10 14:29:58 +02:00
utox39
3214725e58 refactor: rename a function 2025-09-10 14:29:14 +02:00
utox39
f4a8c962e6 refactor: rename a variable 2025-09-10 14:27:46 +02:00
utox39
f7641c24a3 fix(ascii): fix the calculation of the alignment buffer size 2025-09-10 14:26:11 +02:00
utox39
20e2ef80d2 feat: add custom ascii art 2025-09-10 14:21:22 +02:00
10 changed files with 245 additions and 29 deletions

95
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,95 @@
name: Build
on:
push:
branches: [ "main" ]
jobs:
build:
strategy:
matrix:
include:
# Linux x86_64
- os: ubuntu-latest
target: x86_64-linux
runner_arch: x64
setup_deps: |
sudo apt-get update
sudo apt-get install -y libpci-dev
# macOS x86_64
- os: macos-13
target: x86_64-darwin
runner_arch: x64
setup_deps: ""
# macOS aarch64 (Apple Silicon)
- os: macos-latest
target: aarch64-darwin
runner_arch: arm64
setup_deps: ""
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
- name: Setup platform dependencies
if: matrix.setup_deps != ''
run: ${{ matrix.setup_deps }}
- name: Cache Zig
uses: actions/cache@v4
with:
path: |
~/.cache/zig
zig-cache
key: ${{ runner.os }}-${{ matrix.target }}-zig-${{ hashFiles('build.zig', 'build.zig.zon') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-zig-
- name: Build for target
run: |
zig build -Doptimize=ReleaseSafe
mv zig-out/bin/zigfetch zig-out/bin/zigfetch-${{ matrix.target }}
- name: Verify binary
run: |
ls -la zig-out/bin/
file zig-out/bin/zigfetch-${{ matrix.target }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: zigfetch-${{ matrix.target }}
path: zig-out/bin/zigfetch-${{ matrix.target }}
retention-days: 3
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1
- name: Setup dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpci-dev
- name: Run tests
run: |
zig test src/ascii.zig
zig test src/utils.zig

View File

@@ -1,5 +1,18 @@
# Zigfetch # Zigfetch
![Zig](https://img.shields.io/badge/Zig-%23F7A41D.svg?style=flat&logo=zig&logoColor=white)
![GitHub Release](https://img.shields.io/github/v/release/utox39/zigfetch)
![GitHub License](https://img.shields.io/github/license/utox39/zigfetch)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/utox39/zigfetch/build.yml)
![macOS](https://img.shields.io/badge/mac%20os-000000?style=flat&logo=macos&logoColor=F0F0F0)
![Linux](https://img.shields.io/badge/Linux-FCC624?style=flat&logo=linux&logoColor=black)
| Default config | Custom config |
| :-----------------------------------------------------: | :---------------------------------------------------: |
| ![dafault-config](assets/screenshot-default-config.png) | ![custom-config](assets/screenshot-custom-config.png) |
---
- [Description](#description) - [Description](#description)
- [Requirements](#requirements) - [Requirements](#requirements)
- [Installation](#installation) - [Installation](#installation)
@@ -66,6 +79,83 @@ $ touch config.json
$ cp /path/to/zigfetch/config.json ~/.config/zigfetch/config.json $ cp /path/to/zigfetch/config.json ~/.config/zigfetch/config.json
``` ```
#### Modules
Available modules:
- Os
- Kernel
- Uptime
- Packages
- Shell
- Cpu
- Gpu
- Ram
- Swap
- Disk
- Net
- Terminal
- Locale
- Custom
| Module type | Linux | macOS | Windows |
| :---------: | :-------------: | :----------------------: | :-----: |
| os | Yes | Yes | WIP |
| kernel | Yes | Yes | WIP |
| uptime | Yes | Yes | WIP |
| packages | WIP | Yes (Homebrew, Macports) | WIP |
| shell | Yes (bash, zsh) | Yes (bash, zsh) | WIP |
| cpu | Yes | Yes | WIP |
| gpu | Yes | Yes (Apple Silicon only) | WIP |
| ram | Yes | Yes | WIP |
| swap | Yes | Yes | WIP |
| disk | Yes | Yes | WIP |
| net | Yes | Yes | WIP |
| terminal | Yes | Yes | WIP |
| locale | Yes | Yes | WIP |
```json
"modules": [
{
"type": "os",
"key": "OS",
"key_color": "#5E81AC"
},
...
]
```
#### Custom module
```json
"modules": [
{
"type": "custom",
"key": "-----------",
"key_color": "#5E81AC"
},
...
]
```
#### Custom ASCII art
To use an ASCII art of your choice:
```json
"ascii_abs_path": "absolute_path/to/your/ascii_art.txt"
```
Don't use the `~` character.
#### Username and Hostname color
To change the Username and Hostname color (HEX colors only):
```json
"username_hostname_color": "#5E81AC"
```
## Roadtrip ## Roadtrip
- [ ] Add ASCII art for each operating system and Linux distro - [ ] Add ASCII art for each operating system and Linux distro

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

View File

@@ -10,7 +10,7 @@
// This is a [Semantic Version](https://semver.org/). // This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication. // In a future version of Zig it will be used for package deduplication.
.version = "0.20.0", .version = "0.22.1",
// Together with name, this represents a globally unique package // Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the // identifier. This field is generated by the Zig toolchain when the

View File

@@ -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 printAsciiAndModules(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');
@@ -90,7 +95,7 @@ pub fn printAscii(allocator: std.mem.Allocator, sys_info_list: std.array_list.Ma
const ascii_art_items = ascii_art_content_list.items; const ascii_art_items = ascii_art_content_list.items;
const sys_info_items = sys_info_list.items; const sys_info_items = sys_info_list.items;
const terminal_size = try utils.getTerminalSize(); const terminal_size = utils.getTerminalSize() catch utils.TermSize{ .height = 50, .width = 50 };
const terminal_width: usize = @intCast(terminal_size.width); const terminal_width: usize = @intCast(terminal_size.width);
const spacing: usize = 5; const spacing: usize = 5;
@@ -110,7 +115,7 @@ pub fn printAscii(allocator: std.mem.Allocator, sys_info_list: std.array_list.Ma
while (i < max_len) : (i += 1) { while (i < max_len) : (i += 1) {
// Print the ascii art if the width of the terminal is greater than the spacing (5) + the longest ascii art row length + the longest sys info string length // Print the ascii art if the width of the terminal is greater than the spacing (5) + the longest ascii art row length + the longest sys info string length
if (can_print_ascii_art) { if (can_print_ascii_art) {
const alignment_buffer = try allocator.alloc(u8, longest_ascii_art_row_len - (try utils.countCodepoints(ascii_art_items[i])) + spacing); const alignment_buffer = try allocator.alloc(u8, if (i < ascii_art_len) longest_ascii_art_row_len - (try utils.countCodepoints(ascii_art_items[i])) + spacing else longest_ascii_art_row_len + spacing);
@memset(alignment_buffer, ' '); @memset(alignment_buffer, ' ');
if (i < ascii_art_len) { if (i < ascii_art_len) {

View File

@@ -1,5 +1,4 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const ascii = @import("ascii.zig"); const ascii = @import("ascii.zig");
pub const Module = struct { pub const Module = struct {
@@ -9,6 +8,8 @@ pub const Module = struct {
}; };
pub const Config = struct { pub const Config = struct {
ascii_abs_path: ?[]u8 = null,
username_hostname_color: ?[]u8 = null,
modules: []Module, modules: []Module,
}; };
@@ -29,6 +30,18 @@ pub const ModuleType = enum {
custom, custom,
}; };
pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 {
if (config) |c| {
return c.value.ascii_abs_path;
} else return null;
}
pub fn getUsernameHostnameColor(config: ?std.json.Parsed(Config)) ?[]u8 {
if (config) |c| {
return c.value.username_hostname_color;
} else return null;
}
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);
@@ -38,6 +51,7 @@ pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Co
if (module_enum) |m| { if (module_enum) |m| {
try modules_list.append(m); try modules_list.append(m);
} else { } else {
modules_list.deinit();
return error.InvalidModule; return error.InvalidModule;
} }
} }

View File

@@ -41,6 +41,17 @@ pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyer
&getDefaultFormattedLocaleInfo, &getDefaultFormattedLocaleInfo,
}; };
pub fn getFormattedUsernameHostname(allocator: std.mem.Allocator, color: []const u8, username: []const u8, hostname: []const u8) ![]u8 {
return try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
color,
username,
ascii.Reset,
color,
hostname,
ascii.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", ascii.Yellow);
} }

View File

@@ -10,11 +10,11 @@ pub fn main() !void {
const allocator = gpa.allocator(); const allocator = gpa.allocator();
defer _ = gpa.deinit(); defer _ = gpa.deinit();
var sys_info_list = std.array_list.Managed([]u8).init(allocator); var modules_list = std.array_list.Managed([]u8).init(allocator);
defer sys_info_list.deinit(); defer modules_list.deinit();
errdefer { errdefer {
for (sys_info_list.items) |info| { for (modules_list.items) |info| {
allocator.free(info); allocator.free(info);
} }
} }
@@ -27,29 +27,30 @@ pub fn main() !void {
const username = try detection.user.getUsername(allocator); const username = try detection.user.getUsername(allocator);
const hostname = try detection.system.getHostname(allocator); const hostname = try detection.system.getHostname(allocator);
try sys_info_list.append(try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
ascii.Yellow, const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: {
username, var buf: [32]u8 = undefined;
ascii.Reset, const rgb = try ascii.hexColorToRgb(color);
ascii.Yellow, const formatted_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
hostname, break :blk formatted_color;
ascii.Reset, } else ascii.Yellow;
}));
try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname));
allocator.free(hostname); allocator.free(hostname);
allocator.free(username); allocator.free(username);
const separtor_buffer = try allocator.alloc(u8, username.len + hostname.len + 1); const separtor_buffer = try allocator.alloc(u8, username.len + hostname.len + 1);
@memset(separtor_buffer, '-'); @memset(separtor_buffer, '-');
try sys_info_list.append(separtor_buffer); try modules_list.append(separtor_buffer);
if (modules_types.items.len == 0) { if (modules_types.items.len == 0) {
inline for (0..formatters.default_formatters.len) |i| { inline for (0..formatters.default_formatters.len) |i| {
const result = try formatters.default_formatters[i](allocator); const result = try formatters.default_formatters[i](allocator);
switch (result) { switch (result) {
.string => |r| try sys_info_list.append(r), .string => |r| try modules_list.append(r),
.string_arraylist => |r| { .string_arraylist => |r| {
defer r.deinit(); defer r.deinit();
try sys_info_list.appendSlice(r.items); try modules_list.appendSlice(r.items);
}, },
} }
} }
@@ -61,14 +62,14 @@ pub fn main() !void {
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);
switch (result) { switch (result) {
.string => |r| try sys_info_list.append(r), .string => |r| try modules_list.append(r),
.string_arraylist => |r| { .string_arraylist => |r| {
defer r.deinit(); defer r.deinit();
try sys_info_list.appendSlice(r.items); try modules_list.appendSlice(r.items);
}, },
} }
} }
} }
try ascii.printAscii(allocator, sys_info_list); try ascii.printAsciiAndModules(allocator, config.getAsciiPath(conf), modules_list);
} }

View File

@@ -43,7 +43,7 @@ pub fn getTerminalSize() !TermSize {
} }
test "getTerminalSize" { test "getTerminalSize" {
const terminal_size = try getTerminalSize(); const terminal_size = getTerminalSize() catch TermSize{ .height = 50, .width = 50 };
std.debug.print("Height: {}, Width {}\n", .{ terminal_size.height, terminal_size.width }); std.debug.print("Height: {}, Width {}\n", .{ terminal_size.height, terminal_size.width });