deno
deno copied to clipboard
killing a process does not return tty from raw mode
given the following code snippet
async function* read_input() {
while (true) {
const buffer = new Uint8Array(1024);
Deno.setRaw(Deno.stdin.rid, true);
const length = <number>await Deno.stdin.read(buffer);
Deno.setRaw(Deno.stdin.rid, false);
yield buffer
}
}
for await (const input of read_input()) {
console.log(input)
}
if I run pkill deno
in another terminal, I am left with a terminal that is still in raw mode. This means I cannot type things like Ctrl + c
anymore. Its possible that deno is functioning as expected here, not doing any graceful shutdown things when the process is killed. This does come up fairly commonly though however, if I am developing a cli app with keyboard input and I need to stop the process. Essentially it means opening up a new terminal later
the same thing appears to happen when the process exits unexpectedly, though I am having a harder time reproing that
You can listen to sigint signal and do the cleanup there
I believe I cannot based on this issue here: https://github.com/denoland/deno/issues/15479. I will close this issue though because the issue with closing the resource is better outlined there. If that is solved, then I will simply listen for the sigint signal like you outlined