core: add function to get process info from the surface

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:
Jeffrey C. Ollie
2026-03-18 16:36:18 -05:00
parent 1f89ce91d9
commit 89ae0ea6ef
9 changed files with 327 additions and 30 deletions

View File

@@ -135,6 +135,35 @@ 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 => {
const c = b.addTranslateC(.{
.root_source_file = b.path("src/pty/freebsd.c"),
.target = target,
.optimize = optimize,
});
step.root_module.addImport("pty-c", c.createModule());
},
.linux => {
const c = b.addTranslateC(.{
.root_source_file = b.path("src/pty/linux.c"),
.target = target,
.optimize = optimize,
});
step.root_module.addImport("pty-c", c.createModule());
},
.macos => {
const c = b.addTranslateC(.{
.root_source_file = b.path("src/pty/macos.c"),
.target = target,
.optimize = optimize,
});
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