Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69d02a4bb7 | ||
|
|
6a86a81fcc | ||
|
|
a125053c70 | ||
|
|
d9ec3a7de7 | ||
|
|
5f6460f46e | ||
|
|
aab5212e6e | ||
|
|
abff59b7d6 |
@@ -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.1",
|
.version = "0.22.0",
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user