accept and use a preset value

This commit is contained in:
AJ ONeal 2017-03-25 20:17:51 -06:00
parent f078d479b0
commit 6763d727f5
1 changed files with 39 additions and 19 deletions

View File

@ -169,15 +169,6 @@ var form = {
return new PromiseA(function (resolve) {
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 = {
set: function () {
if (!(cbs.onDebounceAsync||cbs.onDebounce)) {
@ -224,10 +215,12 @@ var form = {
rrs.pause();
form.PromiseA.resolve((cbs.onReturnAsync||cbs.onReturn)(rrs, ws, ws._input.join(''), ch)).then(function (normalInput) {
ws.write('\n');
ws.clearLine(); // person just hit enter, they are on the next line
// (and this will clear the status, if any)
// TODO count lines used below and clear all of them
if (!cbs.value) {
ws.write('\n');
ws.clearLine(); // person just hit enter, they are on the next line
// (and this will clear the status, if any)
// TODO count lines used below and clear all of them
}
rrs.setRawMode(false);
var input = ws._input.join('');
@ -235,11 +228,14 @@ var form = {
ws._inputIndex = 0;
resolve({ input: input, result: normalInput });
}, function (err) {
rrs.on('data', onData);
var errmsg = colors.red(err.message);
form.setStatus(rrs, ws, errmsg);
if (!rrs.isTTY) {
return PromiseA.reject(err);
}
rrs.on('data', onData);
rrs.setRawMode(true);
rrs.resume();
});
}
@ -315,6 +311,26 @@ var form = {
// 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);
});
}
@ -326,13 +342,17 @@ var form = {
// TODO write newline?
//ws.moveCursor(0, 1);
ws.write('\n');
ws.clearLine();
ws.cursorTo(0);
if (ws.isTTY) {
ws.clearLine();
ws.cursorTo(0);
}
// write from beginning of line
ws.write(msg);
// restore position
ws.cursorTo(x);
ws.moveCursor(0, -1);
if (ws.isTTY) {
ws.cursorTo(x);
ws.moveCursor(0, -1);
}
}
, println: function (rrs, ws, msg) {