mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-12-18 00:24:58 +00:00
add password to CLI
This commit is contained in:
20
packages/cli/src/stdin.ts
Normal file
20
packages/cli/src/stdin.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export function getStdin(timeout: number = 10): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
// Store the data from stdin in a buffer
|
||||
let buffer = ''
|
||||
process.stdin.on('data', (d) => (buffer += d.toString()))
|
||||
|
||||
// Stop listening for data after the timeout, otherwise hangs indefinitely
|
||||
const t = setTimeout(() => {
|
||||
process.stdin.destroy()
|
||||
resolve('')
|
||||
}, timeout)
|
||||
|
||||
// Listen for end and error events
|
||||
process.stdin.on('end', () => {
|
||||
clearTimeout(t)
|
||||
resolve(buffer.trim())
|
||||
})
|
||||
process.stdin.on('error', reject)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user