diff --git a/dist/session.js b/dist/session.js index 68e14652..96c98931 100755 --- a/dist/session.js +++ b/dist/session.js @@ -136,12 +136,15 @@ session.prompt = function (options, cb) { * Gets the full (normal + mode) delimiter * for this session. * - * @return {String} + * @return {String} or undefined if there is no delimiter * @api public */ session.fullDelimiter = function () { - var result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : ''); + var result; + if (this._delimiter && this._delimiter !== '') { + result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : ''); + } return result; }; @@ -157,7 +160,7 @@ session.delimiter = function (str) { if (str === undefined) { return this._delimiter; } - this._delimiter = String(str).trim() + ' '; + this._delimiter = String(str).trim(); if (this.isLocal()) { this.parent.ui.refresh(); } else { diff --git a/dist/ui.js b/dist/ui.js index f8dc342d..0f5348b3 100755 --- a/dist/ui.js +++ b/dist/ui.js @@ -77,13 +77,11 @@ var UI = function (_EventEmitter) { } else if (_this.parent.session.cancelCommands) { // There are commands running if // cancelCommands function is available. - _this.imprint(); _this.submit(''); _this._sigintCalled = false; _this._sigintCount = 0; _this.parent.session.emit('vorpal_command_cancel'); } else if (String(text).trim() !== '') { - _this.imprint(); _this.submit(''); _this._sigintCalled = false; _this._sigintCount = 0; @@ -265,7 +263,7 @@ var UI = function (_EventEmitter) { inquirer.prompt.prompts.input.prototype.getQuestion = function () { self._activePrompt = this; var message = this.opt.message; - if (this.opt.default !== null && this.status !== 'answered') { + if ((this.opt.default || this.opt.default === false) && this.status !== 'answered') { message += chalk.dim('(' + this.opt.default + ') '); } self.inquirerStdout.push(message); @@ -536,26 +534,6 @@ var UI = function (_EventEmitter) { * @api public */ - }, { - key: 'imprint', - value: function imprint() { - if (!this.parent) { - return this; - } - var val = this._activePrompt.rl.line; - var delimiter = this._lastDelimiter || this.delimiter() || ''; - this.log(delimiter + val); - return this; - } - - /** - * Redraws the inquirer prompt with a new string. - * - * @param {String} str - * @return {UI} - * @api private - */ - }, { key: 'refresh', value: function refresh() { @@ -650,4 +628,4 @@ if (!global.__vorpal.ui.exists) { module.exports = exports = global.__vorpal.ui.exports; } else { module.exports = global.__vorpal.ui.exports; -} \ No newline at end of file +} diff --git a/dist/vorpal.js b/dist/vorpal.js index f62543bb..5195f838 100755 --- a/dist/vorpal.js +++ b/dist/vorpal.js @@ -163,11 +163,20 @@ Vorpal.prototype.parse = function (argv, options) { args[i] = '"' + args[i] + '"'; } } + if (!options.keepAlive) { + // turn off the delimiter since we are + // not into the vorpal context + result.delimiter(''); + } ui.attach(result); this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); } + if (!options.keepAlive) { + // Exits the CLI context as the UI is still attached + this.exec('exit'); + } }); } } @@ -609,6 +618,12 @@ vorpal._prompt = function (data) { return self; } + // this means that no delimiter has been specified + // and we should skip the prompt + if (!ssn.fullDelimiter()) { + return undefined; + } + prompt = ui.prompt({ type: 'input', name: 'command', diff --git a/lib/session.js b/lib/session.js index 058deb3c..88b4c36e 100755 --- a/lib/session.js +++ b/lib/session.js @@ -136,13 +136,15 @@ session.prompt = function (options, cb) { * Gets the full (normal + mode) delimiter * for this session. * - * @return {String} + * @return {String} or undefined if there is no delimiter * @api public */ session.fullDelimiter = function () { - var result = this._delimiter + - ((this._modeDelimiter !== undefined) ? this._modeDelimiter : ''); + var result; + if (this._delimiter && this._delimiter !== '') { + result = this._delimiter + (this._modeDelimiter !== undefined ? this._modeDelimiter : ''); + } return result; }; @@ -158,7 +160,7 @@ session.delimiter = function (str) { if (str === undefined) { return this._delimiter; } - this._delimiter = String(str).trim() + ' '; + this._delimiter = String(str).trim(); if (this.isLocal()) { this.parent.ui.refresh(); } else { diff --git a/lib/ui.js b/lib/ui.js index e049ed4a..1664ead9 100755 --- a/lib/ui.js +++ b/lib/ui.js @@ -65,13 +65,11 @@ class UI extends EventEmitter { } else if (this.parent.session.cancelCommands) { // There are commands running if // cancelCommands function is available. - this.imprint(); this.submit(''); this._sigintCalled = false; this._sigintCount = 0; this.parent.session.emit('vorpal_command_cancel'); } else if (String(text).trim() !== '') { - this.imprint(); this.submit(''); this._sigintCalled = false; this._sigintCount = 0; @@ -492,23 +490,6 @@ class UI extends EventEmitter { return this; } - /** - * Logs the current delimiter and typed data. - * - * @return {UI} - * @api public - */ - - imprint() { - if (!this.parent) { - return this; - } - const val = this._activePrompt.rl.line; - const delimiter = this._lastDelimiter || this.delimiter() || ''; - this.log(delimiter + val); - return this; - } - /** * Redraws the inquirer prompt with a new string. * diff --git a/lib/vorpal.js b/lib/vorpal.js index d23a2a56..17313404 100755 --- a/lib/vorpal.js +++ b/lib/vorpal.js @@ -163,11 +163,20 @@ Vorpal.prototype.parse = function (argv, options) { args[i] = `"${args[i]}"`; } } + if (!options.keepAlive) { + // turn off the delimiter since we are + // not into the vorpal context + result.delimiter(''); + } ui.attach(result); this.exec(args.join(' '), function (err) { if (err !== undefined && err !== null) { throw new Error(err); } + if (!options.keepAlive) { + // Exits the CLI context as the UI is still attached + this.exec('exit'); + } }); } } @@ -604,6 +613,12 @@ vorpal._prompt = function (data) { return self; } + // this means that no delimiter has been specified + // and we should skip the prompt + if (!ssn.fullDelimiter()) { + return undefined; + } + prompt = ui.prompt({ type: 'input', name: 'command',