ruchy-syntax-tools
Version:
Comprehensive syntax highlighting and language support for the Ruchy programming language
60 lines (45 loc) • 1.07 kB
JavaScript
import process from 'node:process';
const ASCII_ETX_CODE = 0x03; // Ctrl+C emits this code
class StdinDiscarder {
start() {
this.
if (this.
this.
}
}
stop() {
if (this.
throw new Error('`stop` called more times than `start`');
}
this.
if (this.
this.
}
}
// No known way to make it work reliably on Windows.
if (process.platform === 'win32' || !process.stdin.isTTY) {
return;
}
process.stdin.setRawMode(true);
process.stdin.on('data', this.
process.stdin.resume();
}
if (!process.stdin.isTTY) {
return;
}
process.stdin.off('data', this.
process.stdin.pause();
process.stdin.setRawMode(false);
}
// Allow Ctrl+C to gracefully exit.
if (chunk[0] === ASCII_ETX_CODE) {
process.emit('SIGINT');
}
}
}
const stdinDiscarder = new StdinDiscarder();
export default stdinDiscarder;