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

View File

@ -169,15 +169,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 +215,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) {
ws.write('\n'); if (!cbs.value) {
ws.clearLine(); // person just hit enter, they are on the next line ws.write('\n');
// (and this will clear the status, if any) ws.clearLine(); // person just hit enter, they are on the next line
// TODO count lines used below and clear all of them // (and this will clear the status, if any)
// 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 +228,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();
}); });
} }
@ -315,6 +311,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,13 +342,17 @@ var form = {
// TODO write newline? // TODO write newline?
//ws.moveCursor(0, 1); //ws.moveCursor(0, 1);
ws.write('\n'); ws.write('\n');
ws.clearLine(); if (ws.isTTY) {
ws.cursorTo(0); ws.clearLine();
ws.cursorTo(0);
}
// write from beginning of line // write from beginning of line
ws.write(msg); ws.write(msg);
// restore position // restore position
ws.cursorTo(x); if (ws.isTTY) {
ws.moveCursor(0, -1); ws.cursorTo(x);
ws.moveCursor(0, -1);
}
} }
, println: function (rrs, ws, msg) { , println: function (rrs, ws, msg) {