|
1 | | -import { ConfirmPrompt } from '@clack/core'; |
| 1 | +import { ConfirmPrompt, settings } from '@clack/core'; |
2 | 2 | import color from 'picocolors'; |
3 | 3 | import { |
4 | 4 | type CommonOptions, |
@@ -26,26 +26,33 @@ export const confirm = (opts: ConfirmOptions) => { |
26 | 26 | output: opts.output, |
27 | 27 | initialValue: opts.initialValue ?? true, |
28 | 28 | render() { |
29 | | - const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; |
| 29 | + const hasGuide = (opts.withGuide ?? settings.withGuide) !== false; |
| 30 | + const title = `${hasGuide ? `${color.gray(S_BAR)}\n` : ''}${symbol(this.state)} ${opts.message}\n`; |
30 | 31 | const value = this.value ? active : inactive; |
31 | 32 |
|
32 | 33 | switch (this.state) { |
33 | | - case 'submit': |
34 | | - return `${title}${color.gray(S_BAR)} ${color.dim(value)}`; |
35 | | - case 'cancel': |
36 | | - return `${title}${color.gray(S_BAR)} ${color.strikethrough( |
| 34 | + case 'submit': { |
| 35 | + const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : ''; |
| 36 | + return `${title}${submitPrefix}${color.dim(value)}`; |
| 37 | + } |
| 38 | + case 'cancel': { |
| 39 | + const cancelPrefix = hasGuide ? `${color.gray(S_BAR)} ` : ''; |
| 40 | + return `${title}${cancelPrefix}${color.strikethrough( |
37 | 41 | color.dim(value) |
38 | | - )}\n${color.gray(S_BAR)}`; |
| 42 | + )}${hasGuide ? `\n${color.gray(S_BAR)}` : ''}`; |
| 43 | + } |
39 | 44 | default: { |
40 | | - return `${title}${color.cyan(S_BAR)} ${ |
| 45 | + const defaultPrefix = hasGuide ? `${color.cyan(S_BAR)} ` : ''; |
| 46 | + const defaultPrefixEnd = hasGuide ? color.cyan(S_BAR_END) : ''; |
| 47 | + return `${title}${defaultPrefix}${ |
41 | 48 | this.value |
42 | 49 | ? `${color.green(S_RADIO_ACTIVE)} ${active}` |
43 | 50 | : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(active)}` |
44 | 51 | } ${color.dim('/')} ${ |
45 | 52 | !this.value |
46 | 53 | ? `${color.green(S_RADIO_ACTIVE)} ${inactive}` |
47 | 54 | : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}` |
48 | | - }\n${color.cyan(S_BAR_END)}\n`; |
| 55 | + }\n${defaultPrefixEnd}\n`; |
49 | 56 | } |
50 | 57 | } |
51 | 58 | }, |
|
0 commit comments