From 9696670d05288b2feea0a6af2228d97466eb94fc Mon Sep 17 00:00:00 2001 From: kabeep Date: Thu, 9 May 2024 22:47:07 +0800 Subject: [PATCH] fix: should not hide cursor while press Ctrl + C in Windows OS --- bin/cli.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/cli.ts b/bin/cli.ts index 08f5648..b06d624 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -1,9 +1,25 @@ #!/usr/bin/env node import Exception from '@kabeep/exception'; +import readline from 'node:readline'; import { hideBin } from 'yargs/helpers'; import yargs from 'yargs/yargs'; import pipeline, { type ArgumentVector, locale } from '../src/index.js'; +if (process.platform === 'win32') { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + rl.on('SIGINT', function () { + process.emit('SIGINT'); + }); +} + +process.on('SIGINT', function () { + process.exit(0); +}); + pipeline( yargs(hideBin(process.argv)) .scriptName('translate')