Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0aec3d8e5b | ||
|
|
dd2f50c79c | ||
|
|
16bb74c47b | ||
|
|
20f9c6e1d5 | ||
|
|
b09443db4d | ||
|
|
dd3b79b32d | ||
|
|
22376139f2 | ||
|
|
a835074ee6 | ||
|
|
3d16102f37 | ||
|
|
24a5e98089 | ||
|
|
f03f7e163c | ||
|
|
69d02a4bb7 | ||
|
|
6a86a81fcc | ||
|
|
a125053c70 | ||
|
|
d9ec3a7de7 | ||
|
|
5f6460f46e | ||
|
|
aab5212e6e | ||
|
|
abff59b7d6 | ||
|
|
1dc0559b8e | ||
|
|
2b32119bc7 | ||
|
|
837b7cd5c4 | ||
|
|
6317269c4f | ||
|
|
989b5b2305 | ||
|
|
c32318dac2 | ||
|
|
c64f2f384d | ||
|
|
c82622cf8e | ||
|
|
9babb021f1 |
95
.github/workflows/build.yml
vendored
Normal file
95
.github/workflows/build.yml
vendored
Normal 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
|
||||||
83
README.md
83
README.md
@@ -2,9 +2,15 @@
|
|||||||
|
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
|
| Default config | Custom config |
|
||||||
|
| :-----------------------------------------------------: | :---------------------------------------------------: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
- [Description](#description)
|
- [Description](#description)
|
||||||
@@ -73,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
|
||||||
|
|||||||
BIN
assets/screenshot-custom-config.png
Normal file
BIN
assets/screenshot-custom-config.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
BIN
assets/screenshot-default-config.png
Normal file
BIN
assets/screenshot-default-config.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
@@ -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.21.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
|
||||||
|
|||||||
@@ -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 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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -10,6 +9,7 @@ pub const Module = struct {
|
|||||||
|
|
||||||
pub const Config = struct {
|
pub const Config = struct {
|
||||||
ascii_abs_path: ?[]u8 = null,
|
ascii_abs_path: ?[]u8 = null,
|
||||||
|
username_hostname_color: ?[]u8 = null,
|
||||||
modules: []Module,
|
modules: []Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +31,15 @@ pub const ModuleType = enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 {
|
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) {
|
pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.array_list.Managed(ModuleType) {
|
||||||
@@ -43,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main.zig
17
src/main.zig
@@ -27,14 +27,15 @@ 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 modules_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);
|
||||||
|
|
||||||
|
|||||||
@@ -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