Skip to content

Commit

Permalink
large prompt follows cli ux required interface
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir committed Feb 13, 2024
1 parent 35fbff3 commit 9bbe6a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
14 changes: 3 additions & 11 deletions ironfish-cli/src/commands/wallet/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,8 @@ export class ImportCommand extends IronfishCommand {
}

async importTTY(): Promise<string> {
let userInput = (
await largePrompt('Paste the output of wallet:export, or your spending key: ')
).trim()

while (userInput.length === 0) {
userInput = (
await largePrompt('Paste the output of wallet:export, or your spending key: ')
).trim()
}

return userInput
return await largePrompt('Paste the output of wallet:export, or your spending key: ', {
required: true,
})
}
}
17 changes: 16 additions & 1 deletion ironfish-cli/src/utils/longPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import readline from 'readline'

// Most effective way to take in a large textual prompt input without affecting UX
export function largePrompt(question: string): Promise<string> {
function fetchResponse(question: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
Expand All @@ -17,3 +17,18 @@ export function largePrompt(question: string): Promise<string> {
})
})
}

export async function largePrompt(
question: string,
options?: {
required?: boolean
},
): Promise<string> {
let userInput = (await fetchResponse(question)).trim()

while (userInput.length === 0 && options?.required) {
userInput = (await fetchResponse(question)).trim()
}

return userInput
}

0 comments on commit 9bbe6a3

Please sign in to comment.