
Spawning a PTY in Rust: How broll Captures Your Terminal Without You Noticing
When you run broll start , something subtle happens. A new shell opens, and it looks exactly like your normal terminal. Your prompt, aliases, keybindings, colors: everything works. But behind the scenes, every byte of output flows through broll's recording pipeline before it reaches your screen. The trick that makes this possible is a pseudo-terminal (PTY). This post explains what PTYs are, how broll spawns one in Rust, how it injects shell hooks using OSC escape sequences to distinguish commands from output, and how it uses the Drop trait to guarantee safe cleanup. What Is a PTY and Why Do You Need One? A PTY is a pair of virtual devices: a "master" side and a "slave" side. The slave side looks like a real terminal to any program connected to it. The master side gives you programmatic access to everything the program writes, and lets you send input as if a human were typing. Without a PTY, you could try capturing output by piping stdout. But that breaks interactive programs. Tools lik
Continue reading on Dev.to
Opens in a new tab




