From 1bf237970c84747373f31c894f461ddd53df194a Mon Sep 17 00:00:00 2001 From: bluwy Date: Sun, 10 Sep 2023 18:01:42 +0800 Subject: [PATCH] feat(shortcuts)!: remove setRawMode --- packages/vite/src/node/shortcuts.ts | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/packages/vite/src/node/shortcuts.ts b/packages/vite/src/node/shortcuts.ts index c5bd4bf0e68ef4..2c604fecfe4550 100644 --- a/packages/vite/src/node/shortcuts.ts +++ b/packages/vite/src/node/shortcuts.ts @@ -1,3 +1,4 @@ +import readline from 'node:readline' import colors from 'picocolors' import type { ViteDevServer } from './server' import { isDefined } from './utils' @@ -36,7 +37,7 @@ export function bindCLIShortcuts( server.config.logger.info( colors.dim(colors.green(' ➜')) + colors.dim(' press ') + - colors.bold('h') + + colors.bold('h + enter') + colors.dim(' to show help'), ) } @@ -49,20 +50,6 @@ export function bindCLIShortcuts( let actionRunning = false const onInput = async (input: string) => { - // ctrl+c or ctrl+d - if (input === '\x03' || input === '\x04') { - try { - if (isDev) { - await server.close() - } else { - server.httpServer.close() - } - } finally { - process.exit(1) - } - return - } - if (actionRunning) return if (input === 'h') { @@ -73,7 +60,7 @@ export function bindCLIShortcuts( ...shortcuts.map( (shortcut) => colors.dim(' press ') + - colors.bold(shortcut.key) + + colors.bold(`${shortcut.key} + enter`) + colors.dim(` to ${shortcut.description}`), ), ].join('\n'), @@ -88,13 +75,9 @@ export function bindCLIShortcuts( actionRunning = false } - process.stdin.setRawMode(true) - - process.stdin.on('data', onInput).setEncoding('utf8').resume() - - server.httpServer.on('close', () => { - process.stdin.off('data', onInput).pause() - }) + const rl = readline.createInterface({ input: process.stdin }) + rl.on('line', onInput) + server.httpServer.on('close', () => rl.close()) } function isDevServer(