3 const BooleanPrompt = require('../types/boolean');
5 class TogglePrompt extends BooleanPrompt {
7 await super.initialize();
8 this.value = this.initial = !!this.options.initial;
9 this.disabled = this.options.disabled || 'no';
10 this.enabled = this.options.enabled || 'yes';
15 this.value = this.initial;
24 this.value = !this.value;
29 if (this.value === true) return this.alert();
34 if (this.value === false) return this.alert();
58 dispatch(ch = '', key) {
59 switch (ch.toLowerCase()) {
69 return this.disable();
77 let active = str => this.styles.primary.underline(str);
79 this.value ? this.disabled : active(this.disabled),
80 this.value ? active(this.enabled) : this.enabled
82 return value.join(this.styles.muted(' / '));
86 let { size } = this.state;
88 let header = await this.header();
89 let prefix = await this.prefix();
90 let separator = await this.separator();
91 let message = await this.message();
93 let output = await this.format();
94 let help = (await this.error()) || (await this.hint());
95 let footer = await this.footer();
97 let prompt = [prefix, message, separator, output].join(' ');
98 this.state.prompt = prompt;
100 if (help && !prompt.includes(help)) prompt += ' ' + help;
103 this.write([header, prompt, footer].filter(Boolean).join('\n'));
104 this.write(this.margin[2]);
109 module.exports = TogglePrompt;