Skip to content

Commit 536631a

Browse files
authored
feat(shortcuts)!: remove setRawMode (#14342)
1 parent 404f30f commit 536631a

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

packages/vite/src/node/shortcuts.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import readline from 'node:readline'
12
import colors from 'picocolors'
23
import type { ViteDevServer } from './server'
34
import { isDefined } from './utils'
@@ -36,7 +37,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
3637
server.config.logger.info(
3738
colors.dim(colors.green(' ➜')) +
3839
colors.dim(' press ') +
39-
colors.bold('h') +
40+
colors.bold('h + enter') +
4041
colors.dim(' to show help'),
4142
)
4243
}
@@ -49,20 +50,6 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
4950
let actionRunning = false
5051

5152
const onInput = async (input: string) => {
52-
// ctrl+c or ctrl+d
53-
if (input === '\x03' || input === '\x04') {
54-
try {
55-
if (isDev) {
56-
await server.close()
57-
} else {
58-
server.httpServer.close()
59-
}
60-
} finally {
61-
process.exit(1)
62-
}
63-
return
64-
}
65-
6653
if (actionRunning) return
6754

6855
if (input === 'h') {
@@ -73,7 +60,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
7360
...shortcuts.map(
7461
(shortcut) =>
7562
colors.dim(' press ') +
76-
colors.bold(shortcut.key) +
63+
colors.bold(`${shortcut.key} + enter`) +
7764
colors.dim(` to ${shortcut.description}`),
7865
),
7966
].join('\n'),
@@ -88,13 +75,9 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
8875
actionRunning = false
8976
}
9077

91-
process.stdin.setRawMode(true)
92-
93-
process.stdin.on('data', onInput).setEncoding('utf8').resume()
94-
95-
server.httpServer.on('close', () => {
96-
process.stdin.off('data', onInput).pause()
97-
})
78+
const rl = readline.createInterface({ input: process.stdin })
79+
rl.on('line', onInput)
80+
server.httpServer.on('close', () => rl.close())
9881
}
9982

10083
function isDevServer(

0 commit comments

Comments
 (0)