refactor(macos): handle the EnvironmentVariableNotFound error for the env vars 'LANG' and 'TERM_PROGRAM'

This commit is contained in:
utox39
2025-05-09 11:52:22 +02:00
parent 55897d5f47
commit 34ff7e827b
2 changed files with 6 additions and 2 deletions

View File

@@ -33,7 +33,9 @@ pub fn getHostname(allocator: std.mem.Allocator) ![]u8 {
} }
pub fn getLocale(allocator: std.mem.Allocator) ![]u8 { pub fn getLocale(allocator: std.mem.Allocator) ![]u8 {
const locale = try std.process.getEnvVarOwned(allocator, "LANG"); const locale = std.process.getEnvVarOwned(allocator, "LANG") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown");
} else return err;
return locale; return locale;
} }

View File

@@ -27,6 +27,8 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
} }
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 { pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
const term_progrm = try std.process.getEnvVarOwned(allocator, "TERM_PROGRAM"); const term_progrm = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown");
} else return err;
return term_progrm; return term_progrm;
} }