-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Description
When using Bun.Terminal with Bun.spawn, writing \x03 (Ctrl+C / ETX character) to the terminal does not send SIGINT to the foreground process group. The character is passed through to the PTY but does not trigger signal handling.
Steps to Reproduce
const terminal = new Bun.Terminal({
cols: 80,
rows: 24,
data: (term, data) => {
process.stdout.write(data);
}
});
const proc = Bun.spawn(['/bin/bash'], {
terminal,
cwd: '/tmp',
env: { TERM: 'xterm-256color', ...process.env }
});
// Later, when user presses Ctrl+C:
terminal.write('\x03'); // This should send SIGINT but doesn'tExpected Behavior
Writing \x03 to the terminal should cause the PTY driver to send SIGINT to the foreground process group, similar to how a real terminal handles Ctrl+C.
Actual Behavior
The \x03 character is written to the PTY but no signal is sent. Long-running commands like sleep 100 cannot be interrupted with Ctrl+C.
Workaround
Currently we work around this by intercepting \x03 and manually calling process.kill('SIGINT'):
if (data === '\x03') {
proc.kill('SIGINT');
terminal.write(data); // Still write to show ^C
return;
}
terminal.write(data);However, this only kills the shell process itself, not necessarily the foreground process group (e.g., if bash spawned a subprocess).
Environment
- Bun version: 1.2.17+
- OS: Linux (tested in Docker container on Ubuntu 22.04)
- Architecture: x86_64
Additional Context
The same issue likely applies to other control characters like:
\x1a(Ctrl+Z) → SIGTSTP\x1c(Ctrl+) → SIGQUIT
In a traditional PTY setup, the terminal driver (configured via stty) handles these control characters and sends the appropriate signals to the foreground process group.