Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69d02a4bb7 | ||
|
|
6a86a81fcc | ||
|
|
a125053c70 | ||
|
|
d9ec3a7de7 | ||
|
|
5f6460f46e | ||
|
|
aab5212e6e | ||
|
|
abff59b7d6 | ||
|
|
1dc0559b8e | ||
|
|
2b32119bc7 | ||
|
|
837b7cd5c4 | ||
|
|
6317269c4f | ||
|
|
989b5b2305 | ||
|
|
c32318dac2 | ||
|
|
c64f2f384d | ||
|
|
c82622cf8e | ||
|
|
9babb021f1 |
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
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// In a future version of Zig it will be used for package deduplication.
|
||||
.version = "0.21.0",
|
||||
.version = "0.22.0",
|
||||
|
||||
// Together with name, this represents a globally unique package
|
||||
// identifier. This field is generated by the Zig toolchain when the
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn printAsciiAndModules(allocator: std.mem.Allocator, ascii_art_path: ?[]u8,
|
||||
const ascii_art_items = ascii_art_content_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 spacing: usize = 5;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const ascii = @import("ascii.zig");
|
||||
|
||||
pub const Module = struct {
|
||||
@@ -10,6 +9,7 @@ pub const Module = struct {
|
||||
|
||||
pub const Config = struct {
|
||||
ascii_abs_path: ?[]u8 = null,
|
||||
username_hostname_color: ?[]u8 = null,
|
||||
modules: []Module,
|
||||
};
|
||||
|
||||
@@ -31,7 +31,15 @@ pub const ModuleType = enum {
|
||||
};
|
||||
|
||||
pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 {
|
||||
return config.?.value.ascii_abs_path;
|
||||
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) {
|
||||
|
||||
@@ -41,6 +41,17 @@ pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyer
|
||||
&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 {
|
||||
return try getFormattedKernelInfo(allocator, "Kernel", ascii.Yellow);
|
||||
}
|
||||
|
||||
17
src/main.zig
17
src/main.zig
@@ -27,14 +27,15 @@ pub fn main() !void {
|
||||
|
||||
const username = try detection.user.getUsername(allocator);
|
||||
const hostname = try detection.system.getHostname(allocator);
|
||||
try modules_list.append(try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{
|
||||
ascii.Yellow,
|
||||
username,
|
||||
ascii.Reset,
|
||||
ascii.Yellow,
|
||||
hostname,
|
||||
ascii.Reset,
|
||||
}));
|
||||
|
||||
const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: {
|
||||
var buf: [32]u8 = undefined;
|
||||
const rgb = try ascii.hexColorToRgb(color);
|
||||
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;
|
||||
} else ascii.Yellow;
|
||||
|
||||
try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname));
|
||||
allocator.free(hostname);
|
||||
allocator.free(username);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn getTerminalSize() !TermSize {
|
||||
}
|
||||
|
||||
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 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user