Skip to content

Commit

Permalink
feat(shortcuts)!: remove setRawMode (#14342)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Sep 21, 2023
1 parent 404f30f commit 536631a
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions packages/vite/src/node/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import readline from 'node:readline'
import colors from 'picocolors'
import type { ViteDevServer } from './server'
import { isDefined } from './utils'
Expand Down Expand Up @@ -36,7 +37,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
server.config.logger.info(
colors.dim(colors.green(' ➜')) +
colors.dim(' press ') +
colors.bold('h') +
colors.bold('h + enter') +
colors.dim(' to show help'),
)
}
Expand All @@ -49,20 +50,6 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
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') {
Expand All @@ -73,7 +60,7 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
...shortcuts.map(
(shortcut) =>
colors.dim(' press ') +
colors.bold(shortcut.key) +
colors.bold(`${shortcut.key} + enter`) +
colors.dim(` to ${shortcut.description}`),
),
].join('\n'),
Expand All @@ -88,13 +75,9 @@ export function bindCLIShortcuts<Server extends ViteDevServer | PreviewServer>(
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(
Expand Down

0 comments on commit 536631a

Please sign in to comment.