Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bcfff5bdc | ||
|
|
42edc5c24b | ||
|
|
537a324275 | ||
|
|
224a7d29d8 | ||
|
|
eb477e5154 | ||
|
|
2d1c7506d8 |
@@ -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.8.1",
|
.version = "0.9.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
|
||||||
|
|||||||
@@ -22,9 +22,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
|||||||
|
|
||||||
_ = try child.wait();
|
_ = 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;
|
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 {
|
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||||
return allocator.dupe(u8, "Unknown");
|
return allocator.dupe(u8, "Unknown");
|
||||||
|
|||||||
@@ -25,9 +25,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
|||||||
|
|
||||||
_ = try child.wait();
|
_ = 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;
|
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 {
|
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||||
return allocator.dupe(u8, "Unknown");
|
return allocator.dupe(u8, "Unknown");
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub const TermSize = struct {
|
|||||||
pub fn getTerminalSize() !TermSize {
|
pub fn getTerminalSize() !TermSize {
|
||||||
// https://github.com/softprops/zig-termsize (https://github.com/softprops/zig-termsize/blob/main/src/main.zig)
|
// 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) {
|
switch (builtin.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
|
|||||||
Reference in New Issue
Block a user