| 54 | input: opts.input, |
| 55 | output: opts.output, |
| 56 | render() { |
| 57 | const hasGuide = opts.withGuide ?? settings.withGuide; |
| 58 | const title = `${hasGuide ? `${styleText('gray', S_BAR)}\n` : ''}${symbol(this.state)} ${opts.message}\n`; |
| 59 | const userInput = this.userInputWithCursor; |
| 60 | const masked = this.masked; |
| 61 | |
| 62 | switch (this.state) { |
| 63 | case 'error': { |
| 64 | const errorPrefix = hasGuide ? `${styleText('yellow', S_BAR)} ` : ''; |
| 65 | const errorPrefixEnd = hasGuide ? `${styleText('yellow', S_BAR_END)} ` : ''; |
| 66 | const maskedText = masked ?? ''; |
| 67 | if (opts.clearOnError) { |
| 68 | this.clear(); |
| 69 | } |
| 70 | return `${title.trim()}\n${errorPrefix}${maskedText}\n${errorPrefixEnd}${styleText('yellow', this.error)}\n`; |
| 71 | } |
| 72 | case 'submit': { |
| 73 | const submitPrefix = hasGuide ? `${styleText('gray', S_BAR)} ` : ''; |
| 74 | const maskedText = masked ? styleText('dim', masked) : ''; |
| 75 | return `${title}${submitPrefix}${maskedText}`; |
| 76 | } |
| 77 | case 'cancel': { |
| 78 | const cancelPrefix = hasGuide ? `${styleText('gray', S_BAR)} ` : ''; |
| 79 | const maskedText = masked ? styleText(['strikethrough', 'dim'], masked) : ''; |
| 80 | return `${title}${cancelPrefix}${maskedText}${ |
| 81 | masked && hasGuide ? `\n${styleText('gray', S_BAR)}` : '' |
| 82 | }`; |
| 83 | } |
| 84 | default: { |
| 85 | const defaultPrefix = hasGuide ? `${styleText('cyan', S_BAR)} ` : ''; |
| 86 | const defaultPrefixEnd = hasGuide ? styleText('cyan', S_BAR_END) : ''; |
| 87 | return `${title}${defaultPrefix}${userInput}\n${defaultPrefixEnd}\n`; |
| 88 | } |
| 89 | } |
| 90 | }, |
| 91 | }).prompt() as Promise<string | symbol>; |
| 92 | }; |