mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2025-12-18 00:24:58 +00:00
add --all option, stdin and password option
This commit is contained in:
@@ -2,19 +2,23 @@ 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()))
|
||||
let t: NodeJS.Timeout
|
||||
|
||||
const dataHandler = (d: Buffer) => (buffer += d.toString())
|
||||
const endHandler = () => {
|
||||
clearTimeout(t)
|
||||
resolve(buffer.trim())
|
||||
}
|
||||
|
||||
// Stop listening for data after the timeout, otherwise hangs indefinitely
|
||||
const t = setTimeout(() => {
|
||||
process.stdin.destroy()
|
||||
t = setTimeout(() => {
|
||||
process.stdin.removeListener('data', dataHandler)
|
||||
process.stdin.removeListener('end', endHandler)
|
||||
process.stdin.pause()
|
||||
resolve('')
|
||||
}, timeout)
|
||||
|
||||
// Listen for end and error events
|
||||
process.stdin.on('end', () => {
|
||||
clearTimeout(t)
|
||||
resolve(buffer.trim())
|
||||
})
|
||||
process.stdin.on('error', reject)
|
||||
process.stdin.on('data', dataHandler)
|
||||
process.stdin.on('end', endHandler)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user