1- import { TextPrompt } from '@clack/core' ;
1+ import { settings , TextPrompt } from '@clack/core' ;
22import color from 'picocolors' ;
33import { type CommonOptions , S_BAR , S_BAR_END , symbol } from './common.js' ;
44
@@ -20,7 +20,9 @@ export const text = (opts: TextOptions) => {
2020 signal : opts . signal ,
2121 input : opts . input ,
2222 render ( ) {
23- const title = `${ color . gray ( S_BAR ) } \n${ symbol ( this . state ) } ${ opts . message } \n` ;
23+ const hasGuide = ( opts ?. withGuide ?? settings . withGuide ) !== false ;
24+ const titlePrefix = `${ hasGuide ? `${ color . gray ( S_BAR ) } \n` : '' } ${ symbol ( this . state ) } ` ;
25+ const title = `${ titlePrefix } ${ opts . message } \n` ;
2426 const placeholder = opts . placeholder
2527 ? color . inverse ( opts . placeholder [ 0 ] ) + color . dim ( opts . placeholder . slice ( 1 ) )
2628 : color . inverse ( color . hidden ( '_' ) ) ;
@@ -30,20 +32,25 @@ export const text = (opts: TextOptions) => {
3032 switch ( this . state ) {
3133 case 'error' : {
3234 const errorText = this . error ? ` ${ color . yellow ( this . error ) } ` : '' ;
33- return `${ title . trim ( ) } \n ${ color . yellow ( S_BAR ) } ${ userInput } \n ${ color . yellow (
34- S_BAR_END
35- ) } ${ errorText } \n`;
35+ const errorPrefix = hasGuide ? `${ color . yellow ( S_BAR ) } ` : '' ;
36+ const errorPrefixEnd = hasGuide ? color . yellow ( S_BAR_END ) : '' ;
37+ return ` ${ title . trim ( ) } \n ${ errorPrefix } ${ userInput } \n ${ errorPrefixEnd } ${ errorText } \n`;
3638 }
3739 case 'submit' : {
3840 const valueText = value ? ` ${ color . dim ( value ) } ` : '' ;
39- return `${ title } ${ color . gray ( S_BAR ) } ${ valueText } ` ;
41+ const submitPrefix = hasGuide ? color . gray ( S_BAR ) : '' ;
42+ return `${ title } ${ submitPrefix } ${ valueText } ` ;
4043 }
4144 case 'cancel' : {
4245 const valueText = value ? ` ${ color . strikethrough ( color . dim ( value ) ) } ` : '' ;
43- return `${ title } ${ color . gray ( S_BAR ) } ${ valueText } ${ value . trim ( ) ? `\n${ color . gray ( S_BAR ) } ` : '' } ` ;
46+ const cancelPrefix = hasGuide ? color . gray ( S_BAR ) : '' ;
47+ return `${ title } ${ cancelPrefix } ${ valueText } ${ value . trim ( ) ? `\n${ cancelPrefix } ` : '' } ` ;
48+ }
49+ default : {
50+ const defaultPrefix = hasGuide ? `${ color . cyan ( S_BAR ) } ` : '' ;
51+ const defaultPrefixEnd = hasGuide ? color . cyan ( S_BAR_END ) : '' ;
52+ return `${ title } ${ defaultPrefix } ${ userInput } \n${ defaultPrefixEnd } \n` ;
4453 }
45- default :
46- return `${ title } ${ color . cyan ( S_BAR ) } ${ userInput } \n${ color . cyan ( S_BAR_END ) } \n` ;
4754 }
4855 } ,
4956 } ) . prompt ( ) as Promise < string | symbol > ;
0 commit comments