1
+ import readline from 'node:readline'
1
2
import colors from 'picocolors'
2
3
import type { ViteDevServer } from './server'
3
4
import { isDefined } from './utils'
@@ -36,7 +37,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
36
37
server . config . logger . info (
37
38
colors . dim ( colors . green ( ' ➜' ) ) +
38
39
colors . dim ( ' press ' ) +
39
- colors . bold ( 'h' ) +
40
+ colors . bold ( 'h + enter ' ) +
40
41
colors . dim ( ' to show help' ) ,
41
42
)
42
43
}
@@ -49,20 +50,6 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
49
50
let actionRunning = false
50
51
51
52
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
-
66
53
if ( actionRunning ) return
67
54
68
55
if ( input === 'h' ) {
@@ -73,7 +60,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
73
60
...shortcuts . map (
74
61
( shortcut ) =>
75
62
colors . dim ( ' press ' ) +
76
- colors . bold ( shortcut . key ) +
63
+ colors . bold ( ` ${ shortcut . key } + enter` ) +
77
64
colors . dim ( ` to ${ shortcut . description } ` ) ,
78
65
) ,
79
66
] . join ( '\n' ) ,
@@ -88,13 +75,9 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
88
75
actionRunning = false
89
76
}
90
77
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 ( ) )
98
81
}
99
82
100
83
function isDevServer (
0 commit comments