.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / enquirer / lib / state.js
1 'use strict';
2
3 const { define, width } = require('./utils');
4
5 class State {
6   constructor(prompt) {
7     let options = prompt.options;
8     define(this, '_prompt', prompt);
9     this.type = prompt.type;
10     this.name = prompt.name;
11     this.message = '';
12     this.header = '';
13     this.footer = '';
14     this.error = '';
15     this.hint = '';
16     this.input = '';
17     this.cursor = 0;
18     this.index = 0;
19     this.lines = 0;
20     this.tick = 0;
21     this.prompt = '';
22     this.buffer = '';
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;
32   }
33
34   clone() {
35     let state = { ...this };
36     state.status = this.status;
37     state.buffer = Buffer.from(state.buffer);
38     delete state.clone;
39     return state;
40   }
41
42   set color(val) {
43     this._color = val;
44   }
45   get color() {
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;
51   }
52
53   set loading(value) {
54     this._loading = value;
55   }
56   get loading() {
57     if (typeof this._loading === 'boolean') return this._loading;
58     if (this.loadingChoices) return 'choices';
59     return false;
60   }
61
62   get status() {
63     if (this.cancelled) return 'cancelled';
64     if (this.submitted) return 'submitted';
65     return 'pending';
66   }
67 }
68
69 module.exports = State;