3 const { define, width } = require('./utils');
7 let options = prompt.options;
8 define(this, '_prompt', prompt);
9 this.type = prompt.type;
10 this.name = prompt.name;
23 this.width = width(options.stdout || process.stdout);
24 Object.assign(this, options);
25 this.name = this.name || this.message;
26 this.message = this.message || this.name;
27 this.symbols = prompt.symbols;
28 this.styles = prompt.styles;
29 this.required = new Set();
30 this.cancelled = false;
31 this.submitted = false;
35 let state = { ...this };
36 state.status = this.status;
37 state.buffer = Buffer.from(state.buffer);
46 let styles = this.prompt.styles;
47 if (this.cancelled) return styles.cancelled;
48 if (this.submitted) return styles.submitted;
49 let color = this._color || styles[this.status];
50 return typeof color === 'function' ? color : styles.pending;
54 this._loading = value;
57 if (typeof this._loading === 'boolean') return this._loading;
58 if (this.loadingChoices) return 'choices';
63 if (this.cancelled) return 'cancelled';
64 if (this.submitted) return 'submitted';
69 module.exports = State;