Merge remote-tracking branch 'origin/preset-value' into v1.0
This commit is contained in:
commit
4ec8aa630e
45
index.js
45
index.js
@ -37,6 +37,7 @@ var form = {
|
|||||||
, _prompt: ''
|
, _prompt: ''
|
||||||
, _input: []
|
, _input: []
|
||||||
, _inputIndex: 0
|
, _inputIndex: 0
|
||||||
|
, isTTY: rws.isTTY
|
||||||
, cursorTo: function (x, y) {
|
, cursorTo: function (x, y) {
|
||||||
if ('number' !== typeof x || (0 !== x && !x)) {
|
if ('number' !== typeof x || (0 !== x && !x)) {
|
||||||
throw new Error('cursorTo(x[, y]): x is not optional and must be a number');
|
throw new Error('cursorTo(x[, y]): x is not optional and must be a number');
|
||||||
@ -169,15 +170,6 @@ var form = {
|
|||||||
|
|
||||||
return new PromiseA(function (resolve) {
|
return new PromiseA(function (resolve) {
|
||||||
var ch;
|
var ch;
|
||||||
|
|
||||||
rrs.setRawMode(true);
|
|
||||||
rrs.setEncoding('utf8');
|
|
||||||
rrs.resume();
|
|
||||||
|
|
||||||
ws.cursorTo(0);
|
|
||||||
ws.write(ws._prompt);
|
|
||||||
//ws.cursorTo(0, ws._prompt.length);
|
|
||||||
|
|
||||||
var debouncer = {
|
var debouncer = {
|
||||||
set: function () {
|
set: function () {
|
||||||
if (!(cbs.onDebounceAsync||cbs.onDebounce)) {
|
if (!(cbs.onDebounceAsync||cbs.onDebounce)) {
|
||||||
@ -224,10 +216,12 @@ var form = {
|
|||||||
rrs.pause();
|
rrs.pause();
|
||||||
|
|
||||||
form.PromiseA.resolve((cbs.onReturnAsync||cbs.onReturn)(rrs, ws, ws._input.join(''), ch)).then(function (normalInput) {
|
form.PromiseA.resolve((cbs.onReturnAsync||cbs.onReturn)(rrs, ws, ws._input.join(''), ch)).then(function (normalInput) {
|
||||||
|
if (!cbs.value) {
|
||||||
ws.write('\n');
|
ws.write('\n');
|
||||||
ws.clearLine(); // person just hit enter, they are on the next line
|
ws.clearLine(); // person just hit enter, they are on the next line
|
||||||
// (and this will clear the status, if any)
|
// (and this will clear the status, if any)
|
||||||
// TODO count lines used below and clear all of them
|
// TODO count lines used below and clear all of them
|
||||||
|
}
|
||||||
rrs.setRawMode(false);
|
rrs.setRawMode(false);
|
||||||
|
|
||||||
var input = ws._input.join('');
|
var input = ws._input.join('');
|
||||||
@ -235,11 +229,14 @@ var form = {
|
|||||||
ws._inputIndex = 0;
|
ws._inputIndex = 0;
|
||||||
resolve({ input: input, result: normalInput });
|
resolve({ input: input, result: normalInput });
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
rrs.on('data', onData);
|
|
||||||
|
|
||||||
var errmsg = colors.red(err.message);
|
var errmsg = colors.red(err.message);
|
||||||
form.setStatus(rrs, ws, errmsg);
|
form.setStatus(rrs, ws, errmsg);
|
||||||
|
if (!rrs.isTTY) {
|
||||||
|
return PromiseA.reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
rrs.on('data', onData);
|
||||||
|
rrs.setRawMode(true);
|
||||||
rrs.resume();
|
rrs.resume();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -249,8 +246,6 @@ var form = {
|
|||||||
var x;
|
var x;
|
||||||
|
|
||||||
if (CTRL_C === ch) {
|
if (CTRL_C === ch) {
|
||||||
console.log("");
|
|
||||||
console.log("received CTRL+C and quit");
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
callback(new Error("cancelled"));
|
callback(new Error("cancelled"));
|
||||||
}
|
}
|
||||||
@ -315,6 +310,26 @@ var form = {
|
|||||||
// will come in and we have to figure out what to do about that
|
// will come in and we have to figure out what to do about that
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cbs.value) {
|
||||||
|
ws._input = require('spliddit')(cbs.value);
|
||||||
|
ws._inputIndex = ws._input.length;
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rrs.isTTY) {
|
||||||
|
return PromiseA.reject("User input is required but stdio is not a TTY");
|
||||||
|
}
|
||||||
|
|
||||||
|
rrs.setRawMode(true);
|
||||||
|
rrs.setEncoding('utf8');
|
||||||
|
rrs.resume();
|
||||||
|
|
||||||
|
if (ws.isTTY) {
|
||||||
|
ws.cursorTo(0);
|
||||||
|
ws.write(ws._prompt);
|
||||||
|
//ws.cursorTo(0, ws._prompt.length);
|
||||||
|
}
|
||||||
rrs.on('data', onData);
|
rrs.on('data', onData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -326,14 +341,18 @@ var form = {
|
|||||||
// TODO write newline?
|
// TODO write newline?
|
||||||
//ws.moveCursor(0, 1);
|
//ws.moveCursor(0, 1);
|
||||||
ws.write('\n');
|
ws.write('\n');
|
||||||
|
if (ws.isTTY) {
|
||||||
ws.clearLine();
|
ws.clearLine();
|
||||||
ws.cursorTo(0);
|
ws.cursorTo(0);
|
||||||
|
}
|
||||||
// write from beginning of line
|
// write from beginning of line
|
||||||
ws.write(msg);
|
ws.write(msg);
|
||||||
// restore position
|
// restore position
|
||||||
|
if (ws.isTTY) {
|
||||||
ws.cursorTo(x);
|
ws.cursorTo(x);
|
||||||
ws.moveCursor(0, -1);
|
ws.moveCursor(0, -1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
, println: function (rrs, ws, msg) {
|
, println: function (rrs, ws, msg) {
|
||||||
if ('string' !== typeof msg) {
|
if ('string' !== typeof msg) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user