3 const Prompt = require('../types/string');
4 const completer = require('../completer');
6 class Input extends Prompt {
9 let history = this.options.history;
10 if (history && history.store) {
11 let initial = history.values || this.initial;
12 this.autosave = !!history.autosave;
13 this.store = history.store;
14 this.data = this.store.get('values') || { past: [], present: initial };
15 this.initial = this.data.present || this.data.past[this.data.past.length - 1];
20 if (!this.store) return this.alert();
21 this.data = completer(action, this.data, this.input);
22 if (!this.data.present) return this.alert();
23 this.input = this.data.present;
24 this.cursor = this.input.length;
29 return this.completion('prev');
33 return this.completion('next');
42 if (!this.store) return;
43 this.data = completer('save', this.data, this.input);
44 this.store.set('values', this.data);
48 if (this.store && this.autosave === true) {
51 return super.submit();
55 module.exports = Input;