Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dc0559b8e | ||
|
|
2b32119bc7 | ||
|
|
837b7cd5c4 | ||
|
|
6317269c4f | ||
|
|
989b5b2305 | ||
|
|
c32318dac2 | ||
|
|
c64f2f384d | ||
|
|
c82622cf8e | ||
|
|
9babb021f1 | ||
|
|
ef8b6bcebd | ||
|
|
acc4563d2d | ||
|
|
ea966cd474 | ||
|
|
3214725e58 | ||
|
|
f4a8c962e6 | ||
|
|
f7641c24a3 | ||
|
|
20e2ef80d2 |
101
.github/workflows/build.yml
vendored
Normal file
101
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
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: Create archive
|
||||||
|
run: |
|
||||||
|
tar -czf zigfetch-${{ matrix.target }}.tar.gz -C 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 }}
|
||||||
|
zigfetch-${{ matrix.target }}.tar.gz
|
||||||
|
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
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
# Zigfetch
|
# Zigfetch
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
- [Description](#description)
|
- [Description](#description)
|
||||||
- [Requirements](#requirements)
|
- [Requirements](#requirements)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
|
|||||||
@@ -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.21.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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ pub const Module = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Config = struct {
|
pub const Config = struct {
|
||||||
|
ascii_abs_path: ?[]u8 = null,
|
||||||
modules: []Module,
|
modules: []Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ pub const ModuleType = enum {
|
|||||||
custom,
|
custom,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 {
|
||||||
|
return config.?.value.ascii_abs_path;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|||||||
20
src/main.zig
20
src/main.zig
@@ -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,7 +27,7 @@ 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}", .{
|
try modules_list.append(try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
|
||||||
ascii.Yellow,
|
ascii.Yellow,
|
||||||
username,
|
username,
|
||||||
ascii.Reset,
|
ascii.Reset,
|
||||||
@@ -40,16 +40,16 @@ pub fn main() !void {
|
|||||||
|
|
||||||
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 +61,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user