prompt-base
Advanced tools
Comparing version 0.3.1 to 0.3.2
13
index.js
@@ -35,2 +35,3 @@ 'use strict'; | ||
this.session = false; | ||
this.called = 0; | ||
this.ui = ui; | ||
@@ -57,3 +58,5 @@ | ||
this.rl = this.ui.rl; | ||
this.resume = this.rl.resume.bind(this.rl); | ||
this.close = this.ui.close.bind(this.ui); | ||
this.pause = this.ui.pause.bind(this.ui); | ||
}; | ||
@@ -132,13 +135,10 @@ | ||
Prompt.prototype.run = function(answers) { | ||
if (this.called) this.resume(); | ||
var name = this.question.name; | ||
var when = this.when(answers); | ||
var ask = when ? this.ask.bind(this) : this.noop; | ||
answers = answers || this.answers; | ||
return new Promise(function(resolve) { | ||
ask(function(value) { | ||
if (typeof value !== 'undefined') { | ||
answers[name] = value; | ||
} | ||
resolve(answers); | ||
resolve(value); | ||
}); | ||
@@ -182,3 +182,4 @@ }); | ||
this.emit('answer', this.answer); | ||
if (!this.session) this.close(); | ||
if (!this.session) this.pause(); | ||
this.called++; | ||
this.callback(this.answer); | ||
@@ -185,0 +186,0 @@ }; |
{ | ||
"name": "prompt-base", | ||
"description": "Base prompt module used for creating custom prompt types for Enquirer.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"homepage": "https://github.com/enquirer/prompt-base", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
@@ -45,3 +45,3 @@ # prompt-base [![NPM version](https://img.shields.io/npm/v/prompt-base.svg?style=flat)](https://www.npmjs.com/package/prompt-base) [![NPM downloads](https://img.shields.io/npm/dm/prompt-base.svg?style=flat)](https://npmjs.org/package/prompt-base) | ||
### [.run](index.js#L129) | ||
### [.run](index.js#L132) | ||
@@ -66,3 +66,3 @@ Initialize a prompt and resolve answers. If `question.when` returns false, | ||
### [.format](index.js#L189) | ||
### [.format](index.js#L190) | ||
@@ -73,3 +73,3 @@ Returns a formatted prompt message. | ||
### [.choices](index.js#L211) | ||
### [.choices](index.js#L212) | ||
@@ -80,3 +80,3 @@ Getter for getting the choices array from the question. | ||
### [.message](index.js#L228) | ||
### [.message](index.js#L229) | ||
@@ -87,3 +87,3 @@ Getter that returns `question.message` after passing it to [format](#format). | ||
### [.prefix](index.js#L246) | ||
### [.prefix](index.js#L247) | ||
@@ -90,0 +90,0 @@ Getter that returns the prefix to use before `question.message`. The |
16233
229