Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da70f9ee06 | ||
|
|
b6628c3135 | ||
|
|
c66d127c4d | ||
|
|
f3c9b6e9a6 | ||
|
|
d55af958e7 | ||
|
|
3bcfff5bdc | ||
|
|
42edc5c24b | ||
|
|
537a324275 | ||
|
|
224a7d29d8 | ||
|
|
eb477e5154 | ||
|
|
2d1c7506d8 |
@@ -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.8.1",
|
||||
.version = "0.10.0",
|
||||
|
||||
// Together with name, this represents a globally unique package
|
||||
// identifier. This field is generated by the Zig toolchain when the
|
||||
|
||||
@@ -26,6 +26,7 @@ pub const ModuleType = enum {
|
||||
net,
|
||||
terminal,
|
||||
locale,
|
||||
custom,
|
||||
};
|
||||
|
||||
pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.ArrayList(ModuleType) {
|
||||
|
||||
@@ -22,6 +22,7 @@ pub const formatters = [_]*const fn (allocator: std.mem.Allocator, key: []const
|
||||
&getFormattedNetInfo,
|
||||
&getFormattedTerminalNameInfo,
|
||||
&getFormattedLocaleInfo,
|
||||
&getFormattedCustom,
|
||||
};
|
||||
|
||||
pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyerror!Result{
|
||||
@@ -207,3 +208,7 @@ pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_co
|
||||
|
||||
return Result{ .string_arraylist = formatted_net_info_list };
|
||||
}
|
||||
|
||||
pub fn getFormattedCustom(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ key_color, key, ascii.Reset }) };
|
||||
}
|
||||
|
||||
@@ -22,9 +22,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
||||
|
||||
_ = try child.wait();
|
||||
|
||||
if (std.mem.indexOf(u8, shell, "bash") != null) {
|
||||
const bash_version = parseBashVersion(output);
|
||||
defer allocator.free(output);
|
||||
return try std.fmt.allocPrint(allocator, "{s} {s}", .{ "bash", bash_version.? });
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
fn parseBashVersion(shell_version_output: []u8) ?[]u8 {
|
||||
const end_index = std.mem.indexOf(u8, shell_version_output, "(");
|
||||
if (end_index == null) return null;
|
||||
|
||||
const version_keyword = "version ";
|
||||
const version_keyword_index = std.mem.indexOf(u8, shell_version_output[0..end_index.?], version_keyword);
|
||||
if (version_keyword_index == null) return null;
|
||||
|
||||
return shell_version_output[version_keyword_index.? + version_keyword.len .. end_index.?];
|
||||
}
|
||||
|
||||
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||
return allocator.dupe(u8, "Unknown");
|
||||
|
||||
@@ -25,9 +25,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
||||
|
||||
_ = try child.wait();
|
||||
|
||||
if (std.mem.indexOf(u8, shell, "bash") != null) {
|
||||
const bash_version = parseBashVersion(output);
|
||||
defer allocator.free(output);
|
||||
return try std.fmt.allocPrint(allocator, "{s} {s}", .{ "bash", bash_version.? });
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
fn parseBashVersion(shell_version_output: []u8) ?[]u8 {
|
||||
const end_index = std.mem.indexOf(u8, shell_version_output, "(");
|
||||
if (end_index == null) return null;
|
||||
|
||||
const version_keyword = "version ";
|
||||
const version_keyword_index = std.mem.indexOf(u8, shell_version_output[0..end_index.?], version_keyword);
|
||||
if (version_keyword_index == null) return null;
|
||||
|
||||
return shell_version_output[version_keyword_index.? + version_keyword.len .. end_index.?];
|
||||
}
|
||||
|
||||
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||
return allocator.dupe(u8, "Unknown");
|
||||
|
||||
@@ -9,7 +9,7 @@ pub const TermSize = struct {
|
||||
pub fn getTerminalSize() !TermSize {
|
||||
// https://github.com/softprops/zig-termsize (https://github.com/softprops/zig-termsize/blob/main/src/main.zig)
|
||||
|
||||
const stdout = std.io.getStdIn();
|
||||
const stdout = std.io.getStdOut();
|
||||
|
||||
switch (builtin.os.tag) {
|
||||
.windows => {
|
||||
@@ -62,6 +62,8 @@ pub fn getLongestSysInfoStringLen(strings: []const []const u8) usize {
|
||||
if (ansi_restet_index != null) {
|
||||
// `start` is the index of the last character of the ANSI reset escape sequence + 1
|
||||
start = ansi_restet_index.? + ansi_reset.len + 1;
|
||||
|
||||
if (start > s.len) continue;
|
||||
}
|
||||
|
||||
longest_len = @max(longest_len, s[start..].len);
|
||||
|
||||
Reference in New Issue
Block a user