core: add function to get process info from the surface (#11639)

This adds a function to the core surface to get process information
about the process(es) running in the terminal. Currently supported is
the PID of the foreground process and the name of the slave PTY.

If there is an error retrieving the information, or the platform does
not support retieving that information `null` is returned.

This will be useful in exposing the foreground PID and slave PTY name to
AppleScript or other APIs.
This commit is contained in:
Mitchell Hashimoto
2026-03-20 12:22:02 -07:00
committed by GitHub
7 changed files with 223 additions and 30 deletions

View File

@@ -135,6 +135,33 @@ pub fn add(
// Every exe needs the terminal options
self.config.terminalOptions().add(b, step.root_module);
// C imports needed to manage/create PTYs
switch (target.result.os.tag) {
.freebsd,
.linux,
.macos,
=> {
const c = b.addTranslateC(.{
.root_source_file = b.path("src/pty.c"),
.target = target,
.optimize = optimize,
});
switch (target.result.os.tag) {
.macos => {
const libc = try std.zig.LibCInstallation.findNative(.{
.allocator = b.allocator,
.target = &target.result,
.verbose = false,
});
c.addSystemIncludePath(.{ .cwd_relative = libc.sys_include_dir.? });
},
else => {},
}
step.root_module.addImport("pty-c", c.createModule());
},
else => {},
}
// Freetype. We always include this even if our font backend doesn't
// use it because Dear Imgui uses Freetype.
_ = b.systemIntegrationOption("freetype", .{}); // Shows it in help