apprt: require envmap for exec-based termio

Supercedes #5726
This commit is contained in:
Mitchell Hashimoto
2025-02-13 12:24:34 -08:00
parent c481bdf704
commit 1fea8028a3
5 changed files with 11 additions and 12 deletions

View File

@ -519,17 +519,18 @@ pub fn init(
// This separate block ({}) is important because our errdefers must // This separate block ({}) is important because our errdefers must
// be scoped here to be valid. // be scoped here to be valid.
{ {
var env_ = rt_surface.defaultTermioEnv() catch |err| env: { var env = rt_surface.defaultTermioEnv() catch |err| env: {
// If an error occurs, we don't want to block surface startup. // If an error occurs, we don't want to block surface startup.
log.warn("error getting env map for surface err={}", .{err}); log.warn("error getting env map for surface err={}", .{err});
break :env null; break :env internal_os.getEnvMap(alloc) catch
std.process.EnvMap.init(alloc);
}; };
errdefer if (env_) |*env| env.deinit(); errdefer env.deinit();
// Initialize our IO backend // Initialize our IO backend
var io_exec = try termio.Exec.init(alloc, .{ var io_exec = try termio.Exec.init(alloc, .{
.command = command, .command = command,
.env = env_, .env = env,
.shell_integration = config.@"shell-integration", .shell_integration = config.@"shell-integration",
.shell_integration_features = config.@"shell-integration-features", .shell_integration_features = config.@"shell-integration-features",
.working_directory = config.@"working-directory", .working_directory = config.@"working-directory",

View File

@ -1030,7 +1030,7 @@ pub const Surface = struct {
}; };
} }
pub fn defaultTermioEnv(self: *const Surface) !?std.process.EnvMap { pub fn defaultTermioEnv(self: *const Surface) !std.process.EnvMap {
const alloc = self.app.core_app.alloc; const alloc = self.app.core_app.alloc;
var env = try internal_os.getEnvMap(alloc); var env = try internal_os.getEnvMap(alloc);
errdefer env.deinit(); errdefer env.deinit();

View File

@ -880,9 +880,8 @@ pub const Surface = struct {
}; };
} }
pub fn defaultTermioEnv(self: *Surface) !?std.process.EnvMap { pub fn defaultTermioEnv(self: *Surface) !std.process.EnvMap {
_ = self; return try internal_os.getEnvMap(self.app.app.alloc);
return null;
} }
fn sizeCallback(window: glfw.Window, width: i32, height: i32) void { fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {

View File

@ -2254,7 +2254,7 @@ fn doPaste(self: *Surface, data: [:0]const u8) void {
}; };
} }
pub fn defaultTermioEnv(self: *Surface) !?std.process.EnvMap { pub fn defaultTermioEnv(self: *Surface) !std.process.EnvMap {
const alloc = self.app.core_app.alloc; const alloc = self.app.core_app.alloc;
var env = try internal_os.getEnvMap(alloc); var env = try internal_os.getEnvMap(alloc);
errdefer env.deinit(); errdefer env.deinit();

View File

@ -682,7 +682,7 @@ pub const ThreadData = struct {
pub const Config = struct { pub const Config = struct {
command: ?[]const u8 = null, command: ?[]const u8 = null,
env: ?EnvMap = null, env: EnvMap,
shell_integration: configpkg.Config.ShellIntegration = .detect, shell_integration: configpkg.Config.ShellIntegration = .detect,
shell_integration_features: configpkg.Config.ShellIntegrationFeatures = .{}, shell_integration_features: configpkg.Config.ShellIntegrationFeatures = .{},
working_directory: ?[]const u8 = null, working_directory: ?[]const u8 = null,
@ -724,8 +724,7 @@ const Subprocess = struct {
// Get our env. If a default env isn't provided by the caller // Get our env. If a default env isn't provided by the caller
// then we get it ourselves. // then we get it ourselves.
var env = cfg.env orelse try internal_os.getEnvMap(alloc); var env = cfg.env;
errdefer if (cfg.env == null) env.deinit();
// If we have a resources dir then set our env var // If we have a resources dir then set our env var
if (cfg.resources_dir) |dir| { if (cfg.resources_dir) |dir| {